/*
 * Copyright (c) 2016 Zibin Zheng <znbin@qq.com>
 * All rights reserved
 */

#include "button.h"
#include <stdint.h>

#define EVENT_CB(ev)   if(handle->cb[ev])handle->cb[ev]((Button*)handle)

//button handle list head.
uint8_t Menu_stat = 0;
uint8_t uart6_tx_cnt = 0;
uint8_t uart5_tx_cnt = 0;
uint8_t uart3_tx_cnt = 0;
uint8_t ir_up_times = 1;
uint8_t nv_up_times = 0;

_Video_chanel Video_chanel;
_NV_Model NV_Model;
_DNR_Pra DNR_Pra;


_OsdLight_Mode OsdLight_Mode; //OSD光线模式
_OsdRun_Mode OsdRun_Mode; //OSD运行模式
_Osd_Infrared_ColorMode Osd_Infrared_ColorMode; //OSD红外模式下的色彩模式
_Osd_Daylight_ColorMode Osd_Daylight_ColorMode; //OSD红外模式下的色彩模式
_MotorRun_Mode MotorRun_Mode; //电机运行模式
_MenuLevel MenuLevel;//菜单等级
_WIFI_Mode	WIFI_Mode; //Wifi运行模式; //Wifi运行模式 WIFY_Mode; //电机运行模式
_MotorStop_Source MotorStop_Source;
_DWR_Pra DWR_Pra;

_OutDoor_Pra OutDoor_Pra;//户外模式
_Correction_Mode Correction_Mode;//罗盘校正

_Bool Flag_PhotoRecordeEnable;//拍照录像启动标识
bool Flag_LsserON = false;    //启光启动标识
bool Flag_ButtonWaiting;

_VL_AmplifierReduce_Num VL_AmplifierReduce_Date =_VL_AmplifierReduce_1;
_IR_AmplifierReduce_Num IR_AmplifierReduce_Date = 1;

static uint8_t KEY_Down_LONG_PRESS_HOLD_Flag;
static uint8_t KEY_Up_LONG_PRESS_HOLD_Flag;


/*********按键结构体定义***********/
struct Button KEY_Menu;
struct Button KEY_Func;
struct Button KEY_Up;
struct Button KEY_Down;
struct Button KEY_Laser;

struct Button JOY_Up;
struct Button JOY_Down;
struct Button JOY_Left;
struct Button JOY_Right;
struct Button JOY_Center;
_Bool Video_stat = Video_IR;

// 红外机芯控制命令定义
const unsigned char Enter_click[] = {0x68, 0xE0, 0x02, 0x01, 0x00, 0x00, 0x4D, 0x01, 0x01, 0x01};
const unsigned char Enter_long[] = {0x68, 0xE0, 0x02, 0x01, 0x00, 0x00, 0x4E, 0x01, 0x01, 0x02};
const unsigned char Up_click[] = {0x68, 0xE0, 0x02, 0x01, 0x00, 0x00, 0x4E, 0x01, 0x02, 0x01};
const unsigned char Up_long[] = {0x68, 0xE0, 0x02, 0x01, 0x00, 0x00, 0x4F, 0x01, 0x02, 0x02};
const unsigned char Down_click[] = {0x68, 0xE0, 0x02, 0x01, 0x00, 0x00, 0x4F, 0x01, 0x03, 0x01};
const unsigned char Down_long[] = {0x68, 0xE0, 0x02, 0x01, 0x00, 0x00, 0x50, 0x01, 0x03, 0x02};
const unsigned char Left_click[] = {0x68, 0xE0, 0x02, 0x01, 0x00, 0x00, 0x50, 0x01, 0x04, 0x01};
const unsigned char Left_long[] = {0x68, 0xE0, 0x02, 0x01, 0x00, 0x00, 0x51, 0x01, 0x04, 0x02};
const unsigned char Right_click[] = {0x68, 0xE0, 0x02, 0x01, 0x00, 0x00, 0x51, 0x01, 0x05, 0x01};
const unsigned char Right_long[] = {0x68, 0xE0, 0x02, 0x01, 0x00, 0x00, 0x52, 0x01, 0x05, 0x02};
const unsigned char Power_click[] = {0x68, 0xE0, 0x02, 0x01, 0x00, 0x00, 0x52, 0x01, 0x06, 0x01};

// 白光模式命令
const unsigned char NV_Prefix[] = {0x02, 0x33};
const unsigned char NV_Suffix[] = {0x00, 0x03};
const unsigned char NV_X_Key = 0x15;
const unsigned char NV_Model_Key = 0x33;

// WiFi命令
unsigned char WiFi_OFF[] = {0x55, 0xAA, 0x00, 0x00, 0x7D, 0xFF};
unsigned char WiFi_ON[] = {0x55, 0xAA, 0x00, 0x01, 0x7A, 0xFF};
unsigned char Capture_OFF[] = {0x55, 0xAA, 0x01, 0x00, 0x68, 0xFF};
unsigned char Capture_ON[] = {0x55, 0xAA, 0x01, 0x01, 0x6F, 0xFF};
unsigned char Take_Photo[] = {0x55, 0xAA, 0x02, 0x01, 0x68, 0xFF};

static struct Button* head_handle = NULL;

static void button_handler(struct Button* handle);

/**
  * @brief  Initializes the button struct handle.
  * @param  handle: the button handle struct.
  * @param  pin_level: read the HAL GPIO of the connected button level.
  * @param  active_level: pressed GPIO level.
  * @param  button_id: the button id.
  * @retval None
  */
void button_init(struct Button* handle, uint8_t(*pin_level)(uint8_t), uint8_t active_level, uint8_t button_id)
{
	memset(handle, 0, sizeof(struct Button));
	handle->event = (uint8_t)NONE_PRESS;
	handle->hal_button_Level = pin_level;
	handle->button_level = handle->hal_button_Level(button_id);
	handle->active_level = active_level;
	handle->button_id = button_id;
}

/**
  * @brief  Attach the button event callback function.
  * @param  handle: the button handle struct.
  * @param  event: trigger event type.
  * @param  cb: callback function.
  * @retval None
  */
void button_attach(struct Button* handle, PressEvent event, BtnCallback cb)
{
	handle->cb[event] = cb;
}

/**
  * @brief  Inquire the button event happen.
  * @param  handle: the button handle struct.
  * @retval button event.
  */
PressEvent get_button_event(struct Button* handle)
{
	return (PressEvent)(handle->event);
}

/**
  * @brief  Button driver core function, driver state machine.
  * @param  handle: the button handle struct.
  * @retval None
  */
static void button_handler(struct Button* handle)
{
	uint8_t read_gpio_level = handle->hal_button_Level(handle->button_id);

	//ticks counter working..
	if((handle->state) > 0) handle->ticks++;

	/*------------button debounce handle---------------*/
	if(read_gpio_level != handle->button_level) { //not equal to prev one
		//continue read 3 times same new level change
		if(++(handle->debounce_cnt) >= DEBOUNCE_TICKS) {
			handle->button_level = read_gpio_level;
			handle->debounce_cnt = 0;
		}
	} else { //level not change ,counter reset.
		handle->debounce_cnt = 0;
	}

	/*-----------------State machine-------------------*/
	switch (handle->state) {
	case 0:
		if(handle->button_level == handle->active_level) {	//start press down
			handle->event = (uint8_t)PRESS_DOWN;
			EVENT_CB(PRESS_DOWN);
			handle->ticks = 0;
			handle->repeat = 1;
			handle->state = 1;
		} else {
			handle->event = (uint8_t)NONE_PRESS;
		}
		break;

	case 1:
		if(handle->button_level != handle->active_level) { //released press up
			handle->event = (uint8_t)PRESS_UP;
			EVENT_CB(PRESS_UP);
			handle->ticks = 0;
			handle->state = 2;
		} else if(handle->ticks > LONG_TICKS) {
			handle->event = (uint8_t)LONG_PRESS_START;
			EVENT_CB(LONG_PRESS_START);
			handle->state = 5;
		}
		break;

	case 2:
		if(handle->button_level == handle->active_level) { //press down again
			handle->event = (uint8_t)PRESS_DOWN;
			EVENT_CB(PRESS_DOWN);
			handle->repeat++;
			EVENT_CB(PRESS_REPEAT); // repeat hit
			handle->ticks = 0;
			handle->state = 3;
		} else if(handle->ticks > SHORT_TICKS) { //released timeout
			if(handle->repeat == 1) {
				handle->event = (uint8_t)SINGLE_CLICK;
				EVENT_CB(SINGLE_CLICK);
			} else if(handle->repeat == 2) {
				handle->event = (uint8_t)DOUBLE_CLICK;
				EVENT_CB(DOUBLE_CLICK); // repeat hit
			}
			handle->state = 0;
		}
		break;

	case 3:
		if(handle->button_level != handle->active_level) { //released press up
			handle->event = (uint8_t)PRESS_UP;
			EVENT_CB(PRESS_UP);
			if(handle->ticks < SHORT_TICKS) {
				handle->ticks = 0;
				handle->state = 2; //repeat press
			} else {
				handle->state = 0;
			}
		} else if(handle->ticks > SHORT_TICKS) { // long press up
			handle->state = 0;
		}
		break;

	case 5:
		if(handle->button_level == handle->active_level) {
			//continue hold trigger
			handle->event = (uint8_t)LONG_PRESS_HOLD;
			EVENT_CB(LONG_PRESS_HOLD);
		} else { //releasd
			handle->event = (uint8_t)PRESS_UP;
			EVENT_CB(PRESS_UP);
			handle->state = 0; //reset
		}
		break;
	default:
		handle->state = 0; //reset
		break;
	}
}

/**
  * @brief  Start the button work, add the handle into work list.
  * @param  handle: target handle struct.
  * @retval 0: succeed. -1: already exist.
  */
int button_start(struct Button* handle)
{
	struct Button* target = head_handle;
	while(target) {
		if(target == handle) return -1;	//already exist.
		target = target->next;
	}
	handle->next = head_handle;
	head_handle = handle;
	return 0;
}

/**
  * @brief  Stop the button work, remove the handle off work list.
  * @param  handle: target handle struct.
  * @retval None
  */
void button_stop(struct Button* handle)
{
	struct Button** curr;
	for(curr = &head_handle; *curr; ) {
		struct Button* entry = *curr;
		if(entry == handle) {
			*curr = entry->next;
//			free(entry);
			return;//glacier add 2021-8-18
		} else {
			curr = &entry->next;
		}
	}
}

/**
  * @brief  background ticks, timer repeat invoking interval 5ms.
  * @param  None.
  * @retval None
  */
void button_ticks(void)
{
	struct Button* target;
	for(target=head_handle; target; target=target->next) {
		button_handler(target);
	}
}

void key_io_init(void)
{
	gpio_init_type gpio_init_struct;
	crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
	crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
	gpio_default_para_init(&gpio_init_struct);

	gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
	gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
	gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
	gpio_init_struct.gpio_pins = GPIO_PINS_8 | GPIO_PINS_9 | GPIO_PINS_7;
	gpio_init_struct.gpio_pull = GPIO_PULL_UP;
	gpio_init(GPIOB, &gpio_init_struct);
	
	gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
	gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
	gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
	gpio_init_struct.gpio_pins = GPIO_PINS_2;
	gpio_init_struct.gpio_pull = GPIO_PULL_UP;
	gpio_init(GPIOH, &gpio_init_struct);


	gpio_init_struct.gpio_pins = GPIO_PINS_15;
	gpio_init(GPIOA, &gpio_init_struct);
}

void Joy_io_init(void)
{
	gpio_init_type gpio_init_struct;
	crm_periph_clock_enable(CRM_GPIOH_PERIPH_CLOCK, TRUE);
	crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE);
	gpio_default_para_init(&gpio_init_struct);

	gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
	gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
	gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
	gpio_init_struct.gpio_pins = GPIO_PINS_0 | GPIO_PINS_1;
	gpio_init_struct.gpio_pull = GPIO_PULL_UP;
	gpio_init(GPIOH, &gpio_init_struct);


	gpio_init_struct.gpio_pins = GPIO_PINS_13 | GPIO_PINS_14 | GPIO_PINS_15;
	gpio_init(GPIOC, &gpio_init_struct);
}





#include "at32f435_437_gpio.h"
_Button_IDs Button_IDs;

// 按键键值轮询函数
unsigned char read_key_level(unsigned char button_id)
{
    // you can share the GPIO read function with multiple Buttons
    switch (button_id)
    {
    case KEY_Func_id:
        return gpio_input_data_bit_read(GPIOB, GPIO_PINS_9);
    case KEY_Menu_id:
        return gpio_input_data_bit_read(GPIOB, GPIO_PINS_8);
    case KEY_Down_id:
        return gpio_input_data_bit_read(GPIOA, GPIO_PINS_15);
    case KEY_Up_id:
        return gpio_input_data_bit_read(GPIOB, GPIO_PINS_7);
	case KEY_Laser_id:
        return gpio_input_data_bit_read(GPIOH, GPIO_PINS_2);
		
		case JOY_Up_id:
        return gpio_input_data_bit_read(GPIOC, GPIO_PINS_13);
    case JOY_Down_id:
        return gpio_input_data_bit_read(GPIOC, GPIO_PINS_14);
    case JOY_Left_id:
        return gpio_input_data_bit_read(GPIOC, GPIO_PINS_15);
    case JOY_Right_id:
        return gpio_input_data_bit_read(GPIOH, GPIO_PINS_0);
		case JOY_Center_id:
        return gpio_input_data_bit_read(GPIOH, GPIO_PINS_1);
    default:
        return Null;
    }
}

/*
KEY_Menu 短按拍照 长按录像 录像中图标闪烁 第一次按开供电（那上电初始化是什么界面，不应该是直接跳到拍或录像吗:	上电默认清屏状态，必须按开启电源才有显示）
					
KEY_Func 红外模式下：切换为伪彩  可见光模式下：切换图像模式 彩色，黑白，透雾（上电是什么模式： 白光）
KEY_Up 	红外调焦+
KEY_Down 	红外调焦-
*/

#if MBT_900

void ButtonInit(void)
{
	
	//一级菜单
	key_io_init();

	/**********************************按键初始化***************************************/
	button_init(&KEY_Menu, read_key_level, KEY_ON, KEY_Menu_id); 	// PB8
	button_init(&KEY_Func, read_key_level, KEY_ON, KEY_Func_id); 	//PB9
	button_init(&KEY_Up, read_key_level, KEY_ON, KEY_Up_id);			//PC13
	button_init(&KEY_Down, read_key_level, KEY_ON, KEY_Down_id);	//PC14
	button_init(&KEY_Laser, read_key_level, KEY_ON, KEY_Laser_id);	//PC14

	button_attach(&KEY_Menu, SINGLE_CLICK, KEY_MENU_SINGLE_Click_Handler);
	button_attach(&KEY_Menu, DOUBLE_CLICK, KEY_MENU_DOUBLE_Click_Handler);
	button_attach(&KEY_Menu, LONG_PRESS_START, KEY_MENU_LONG_PRESS_START_Handler);
	button_attach(&KEY_Menu, LONG_PRESS_HOLD, KEY_MENU_LONG_PRESS_HOLD_Handler);

	button_attach(&KEY_Func, SINGLE_CLICK, KEY_FUNC_SINGLE_Click_Handler);
	button_attach(&KEY_Func, DOUBLE_CLICK, KEY_FUNC_DOUBLE_Click_Handler);
	button_attach(&KEY_Func, LONG_PRESS_START, KEY_FUNC_LONG_PRESS_START_Handler);
	button_attach(&KEY_Func, LONG_PRESS_HOLD, KEY_FUNC_LONG_PRESS_HOLD_Handler);

	button_attach(&KEY_Up, SINGLE_CLICK, KEY_UP_SINGLE_Click_Handler);
	button_attach(&KEY_Up, DOUBLE_CLICK, KEY_UP_DOUBLE_Click_Handler);
	button_attach(&KEY_Up, LONG_PRESS_START, KEY_UP_LONG_PRESS_START_Handler);
	button_attach(&KEY_Up, LONG_PRESS_HOLD, KEY_UP_LONG_PRESS_HOLD_Handler);
	button_attach(&KEY_Up, PRESS_UP, KEY_UP_PRESS_UP);

	button_attach(&KEY_Down, SINGLE_CLICK, KEY_DOWN_SINGLE_Click_Handler);
	button_attach(&KEY_Down, DOUBLE_CLICK, KEY_DOWN_DOUBLE_Click_Handler);
	button_attach(&KEY_Down, LONG_PRESS_START, KEY_DOWN_LONG_PRESS_START_Handler);
	button_attach(&KEY_Down, LONG_PRESS_HOLD, KEY_DOWN_LONG_PRESS_HOLD_Handler);
	button_attach(&KEY_Down, PRESS_UP, KEY_DOWN_PRESS_UP);

	button_attach(&KEY_Laser, SINGLE_CLICK, KEY_Laser_SINGLE_Click_Handler);
	button_attach(&KEY_Laser, DOUBLE_CLICK, KEY_Laser_DOUBLE_Click_Handler);
	button_attach(&KEY_Laser, LONG_PRESS_START, KEY_Laser_LONG_PRESS_START_Handler);
	button_attach(&KEY_Laser, LONG_PRESS_HOLD, KEY_Laser_LONG_PRESS_HOLD_Handler);
	button_attach(&KEY_Laser, PRESS_UP, KEY_Laser_PRESS_UP);

	button_start(&KEY_Menu);
	button_start(&KEY_Func);
	button_start(&KEY_Up);
	button_start(&KEY_Down);
	button_start(&KEY_Laser);


	//二级菜单
	Joy_io_init();

	/**********************************按键初始化***************************************/
	button_init(&JOY_Up, read_key_level, KEY_ON, JOY_Up_id); 	// PB8
	button_init(&JOY_Down, read_key_level, KEY_ON, JOY_Down_id); 	//PB9
	button_init(&JOY_Left, read_key_level, KEY_ON, JOY_Left_id);			//PC13
	button_init(&JOY_Right, read_key_level, KEY_ON, JOY_Right_id);	//PC14
	button_init(&JOY_Center, read_key_level, KEY_ON, JOY_Center_id);	//PC14

	button_attach(&JOY_Up, SINGLE_CLICK, JOY_Up_SINGLE_Click_Handler);
	button_attach(&JOY_Up, DOUBLE_CLICK, JOY_Up_DOUBLE_Click_Handler);
	button_attach(&JOY_Up, LONG_PRESS_START, JOY_Up_LONG_PRESS_START_Handler);
	button_attach(&JOY_Up, LONG_PRESS_HOLD, JOY_Up_LONG_PRESS_HOLD_Handler);
	button_attach(&JOY_Up, PRESS_UP, JOY_Up_PRESS_UP);

	button_attach(&JOY_Down, SINGLE_CLICK, JOY_Down_SINGLE_Click_Handler);
	button_attach(&JOY_Down, DOUBLE_CLICK, JOY_Down_DOUBLE_Click_Handler);
	button_attach(&JOY_Down, LONG_PRESS_START, JOY_Down_LONG_PRESS_START_Handler);
	button_attach(&JOY_Down, LONG_PRESS_HOLD, JOY_Down_LONG_PRESS_HOLD_Handler);
	button_attach(&JOY_Down, PRESS_UP, JOY_Down_PRESS_UP);

	button_attach(&JOY_Left, SINGLE_CLICK, JOY_Left_SINGLE_Click_Handler);
	button_attach(&JOY_Left, DOUBLE_CLICK, JOY_Left_DOUBLE_Click_Handler);
	button_attach(&JOY_Left, LONG_PRESS_START, JOY_Left_LONG_PRESS_START_Handler);
	button_attach(&JOY_Left, LONG_PRESS_HOLD, JOY_Left_LONG_PRESS_HOLD_Handler);

	button_attach(&JOY_Right, SINGLE_CLICK, JOY_Right_SINGLE_Click_Handler);
	button_attach(&JOY_Right, DOUBLE_CLICK, JOY_Right_DOUBLE_Click_Handler);
	button_attach(&JOY_Right, LONG_PRESS_START, JOY_Right_LONG_PRESS_START_Handler);
	button_attach(&JOY_Right, LONG_PRESS_HOLD, JOY_Right_LONG_PRESS_HOLD_Handler);

	button_attach(&JOY_Center, SINGLE_CLICK, JOY_Center_SINGLE_Click_Handler);
	button_attach(&JOY_Center, DOUBLE_CLICK, JOY_Center_DOUBLE_Click_Handler);
	button_attach(&JOY_Center, LONG_PRESS_START, JOY_Center_LONG_PRESS_START_Handler);
	button_attach(&JOY_Center, LONG_PRESS_HOLD, JOY_Center_LONG_PRESS_HOLD_Handler);

	button_start(&JOY_Up);
	button_start(&JOY_Down);
	button_start(&JOY_Left);
	button_start(&JOY_Right);
	button_start(&JOY_Center);
}

// KEY_Menu 按键回调函数 短按切换拍照或拍照
uint8_t KEY_MENU_SINGLE_Click_Handler(void *btn)
{
	_OsdRun_Mode Photo_quen;
	
	if(Flag_PhotoRecordeEnable == FALSE) //判断启动
		{
			return 1;
		}
		
	if(MenuLevel != _MainMenu) //菜单级别
		{
			return 1;
		}
		
	switch(OsdLight_Mode)
			{
				case _Daylight:
					if(OsdRun_Mode == _RecordMode) //录像
					{
						Rec_OFF();//结束录像
						OsdRun_Mode = _PhotoMode;//切换拍照模式
						Set_Osd_PhotoRecord(OsdRun_Mode);
						OsdRefresh_Family[_PhotoRecord].Refresh_Flag = Refresh_yes;
						
					}
					else if(OsdRun_Mode == _PhotoMode) //单击拍照 闪烁
					{
						//OsdRun_Mode = _PhotoMode;//切拍照
						Set_Osd_PhotoRecord(OsdRun_Mode);
						OsdRefresh_Family[_PhotoRecord].Refresh_Flag = Refresh_yes;
						Photo_quen = _PhotoMode;
						TakePhoto(); //拍照
						xQueueSend(Photo_QueueHandle,&Photo_quen,0);
					}
					break;
					
				case _Infrared:
					if(OsdRun_Mode == _RecordMode) //录像
					{
						Rec_OFF();//结束录像
						OsdRun_Mode = _PhotoMode;//切换拍照模式
						Set_Osd_PhotoRecord(OsdRun_Mode);
						OsdRefresh_Family[_PhotoRecord].Refresh_Flag = Refresh_yes;
						
					}
					else if(OsdRun_Mode == _PhotoMode) //单击拍照 闪烁
					{
						//OsdRun_Mode = _PhotoMode;//切拍照
						Set_Osd_PhotoRecord(OsdRun_Mode);
						OsdRefresh_Family[_PhotoRecord].Refresh_Flag = Refresh_yes;
						Photo_quen = _PhotoMode;
						TakePhoto(); //拍照
						xQueueSend(Photo_QueueHandle,&Photo_quen,0);
					}
					break;
					
				default :
					break;
				}
		return 1;
}

uint8_t KEY_MENU_DOUBLE_Click_Handler(void *btn)
{
	if(MenuLevel != _MainMenu) //菜单级别
		{
			return 1;
		}
    // do something...
		return 1;
}

//长按 切换录像
uint8_t KEY_MENU_LONG_PRESS_START_Handler(void *btn)
{
		if(MenuLevel != _MainMenu) //菜单级别
		{
			return 1;
		}
      if(Flag_PhotoRecordeEnable == FALSE) //判断启动
		{
			Flag_PhotoRecordeEnable = TRUE;
			
			//默认拍照模式
			OsdRun_Mode = _PhotoMode;//切拍照
			Set_Osd_PhotoRecord(OsdRun_Mode);
			OsdRefresh_Family[_PhotoRecord].Refresh_Flag = Refresh_yes;
			
			OsdRefresh_Family[_VL_PR].Data = 1; //拍照录像模式启动
			//DecToHexToAscii(OsdRefresh_Family[_PR].Data, 0, OsdRefresh_Family[_PR].Module_addr, 1);
			OsdRefresh_Family[_VL_PR].Module_addr[0] = osd_ON;
			OsdRefresh_Family[_VL_PR].Module_addr[1] = osd_NONE;
			OsdRefresh_Family[_VL_PR].Module_addr[2] = '\r';
			
			OsdRefresh_Family[_IR_PR].Data = 1; //拍照录像模式启动
			//DecToHexToAscii(OsdRefresh_Family[_PR].Data, 0, OsdRefresh_Family[_PR].Module_addr, 1);
			OsdRefresh_Family[_IR_PR].Module_addr[0] = osd_ON;
			OsdRefresh_Family[_IR_PR].Module_addr[1] = osd_NONE;
			OsdRefresh_Family[_IR_PR].Module_addr[2] = '\r';
			return 1;
		}
		

 switch(OsdLight_Mode)
	{
		case _Daylight:

			OsdRun_Mode = _RecordMode;//切录像
			Set_Osd_PhotoRecord(OsdRun_Mode);
			OsdRefresh_Family[_PhotoRecord].Refresh_Flag = Refresh_yes;
		
			OsdRefresh_Family[_VL_PR].Data = 1; //拍照录像模式启动
			//DecToHexToAscii(OsdRefresh_Family[_PR].Data, 0, OsdRefresh_Family[_PR].Module_addr, 1);
			OsdRefresh_Family[_VL_PR].Module_addr[0] = osd_ON;
			OsdRefresh_Family[_VL_PR].Module_addr[1] = osd_NONE;
			OsdRefresh_Family[_VL_PR].Module_addr[2] = '\r';
			Rec_ON();//开始录像
			break;
		
		case _Infrared:
			OsdRun_Mode = _RecordMode;//切录像
			Set_Osd_PhotoRecord(OsdRun_Mode);
			OsdRefresh_Family[_PhotoRecord].Refresh_Flag = Refresh_yes;
		
			OsdRefresh_Family[_IR_PR].Data = 1; //拍照录像模式启动
			//DecToHexToAscii(OsdRefresh_Family[_PR].Data, 0, OsdRefresh_Family[_PR].Module_addr, 1);
			OsdRefresh_Family[_IR_PR].Module_addr[0] = osd_ON;
			OsdRefresh_Family[_IR_PR].Module_addr[1] = osd_NONE;
			OsdRefresh_Family[_IR_PR].Module_addr[2] = '\r';
			Rec_ON();//开始录像
			break;
		
		default :
			break;
	}
		
	return 1;
}

uint8_t KEY_MENU_LONG_PRESS_HOLD_Handler(void *btn)
{
	if(MenuLevel != _MainMenu) //菜单级别
		{
			return 1;
		}
    // do something...
		return 1;
}


uint8_t KEY_FUNC_SINGLE_Click_Handler(void *btn)
{
if(MenuLevel != _MainMenu) //菜单级别
		{
			return 1;
		}
	// do something...
	switch(OsdLight_Mode)
	{
		case _Daylight:
			switch(Osd_Daylight_ColorMode)
			{
				case _Auto://自动
					Osd_Daylight_ColorMode++;
					Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
					OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
					Uart6Send(VL_Mode_Defog_OFF_Cmd,MyStrlen(VL_Mode_Defog_OFF_Cmd));
					Uart6Send(VL_Mode_Day_Cmd,MyStrlen(VL_Mode_Day_Cmd));
					break;
				case _Day://彩色
					Osd_Daylight_ColorMode++;
					Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
					OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
					Uart6Send(VL_Mode_Defog_ON_Cmd,MyStrlen(VL_Mode_Defog_ON_Cmd));
					Uart6Send(VL_Mode_Defog_Low_Cmd,MyStrlen(VL_Mode_Defog_Low_Cmd));
					break;
				case _Defog_Low://透雾
					Osd_Daylight_ColorMode ++;
					Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
					OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
					Uart6Send(VL_Mode_Defog_ON_Cmd,MyStrlen(VL_Mode_Defog_ON_Cmd));
					Uart6Send(VL_Mode_Defog_Mid_Cmd,MyStrlen(VL_Mode_Defog_Mid_Cmd));
					break;
				case _Defog_Mid://透雾
					Osd_Daylight_ColorMode ++;
					Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
					OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
					Uart6Send(VL_Mode_Defog_ON_Cmd,MyStrlen(VL_Mode_Defog_ON_Cmd));
					Uart6Send(VL_Mode_Defog_Hig_Cmd,MyStrlen(VL_Mode_Defog_Hig_Cmd));
					break;
				case _Defog_Hig://透雾
					Osd_Daylight_ColorMode ++;
					Osd_Daylight_ColorMode = _Night;
					Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
					OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
					Uart6Send(VL_Mode_Defog_OFF_Cmd,MyStrlen(VL_Mode_Defog_OFF_Cmd));
					Uart6Send(VL_Mode_Night_Cmd,MyStrlen(VL_Mode_Night_Cmd));
					break;
				case _Night://黑白
					Osd_Daylight_ColorMode = _Auto;
					Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
					OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
					Uart6Send(VL_Mode_Defog_OFF_Cmd,MyStrlen(VL_Mode_Defog_OFF_Cmd));
					Uart6Send(VL_Mode_Auto_Cmd,MyStrlen(VL_Mode_Auto_Cmd));
					break;
				default:
					break;
				
			}
			break;
			
			case _Infrared:
				Osd_Infrared_ColorMode ++;
			switch(Osd_Infrared_ColorMode)
			{
				case _WhiteHot://白热
					OsdRefresh_Family[_IR_Polar].Data =	Osd_Infrared_ColorMode;
					Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
					OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
					Uart3Send(IR_Polar_WHot_Cmd,MyStrlen(IR_Polar_WHot_Cmd));
					break;
				case _BlackHot://黑热
					//Osd_Infrared_ColorMode ++;
					OsdRefresh_Family[_IR_Polar].Data =	Osd_Infrared_ColorMode;
					Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
					OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
					Uart3Send(IR_Polar_BHot_Cmd,MyStrlen(IR_Polar_BHot_Cmd));
					break;
#if ChengDu				
				case _Rainbow://彩红
					//Osd_Infrared_ColorMode ++;
					OsdRefresh_Family[_IR_Polar].Data =	Osd_Infrared_ColorMode;
					Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
					OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
					Uart3Send(IR_Polar_RainBow_Cmd,MyStrlen(IR_Polar_RainBow_Cmd));
					break;
#elif BT656
			
#endif				
				case _Iron://热金属
					//Osd_Infrared_ColorMode ++;
					OsdRefresh_Family[_IR_Polar].Data =	Osd_Infrared_ColorMode;
					Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
					OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
					Uart3Send(IR_Polar_Iron_Cmd,MyStrlen(IR_Polar_Iron_Cmd));
					break;
				case _GreenHot://绿热
					//Osd_Infrared_ColorMode = _GreenHot;
					OsdRefresh_Family[_IR_Polar].Data = Osd_Infrared_ColorMode,
					Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
					OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
					Uart3Send(IR_Polar_Green_Cmd,MyStrlen(IR_Polar_Green_Cmd));
					break;
				default:
					Osd_Infrared_ColorMode = _WhiteHot;
					OsdRefresh_Family[_IR_Polar].Data =	Osd_Infrared_ColorMode;
					Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
					OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
					Uart3Send(IR_Polar_WHot_Cmd,MyStrlen(IR_Polar_WHot_Cmd));
					break;
			}
			

				
		default :
			break;
	}
	return 1;
}


// KEY_Func 按键回调函数
uint8_t KEY_FUNC_DOUBLE_Click_Handler(void *btn)
{
	if(MenuLevel == _ConfigMenu) //菜单级别
	{
		return 1;
	}
// do something...
	return 1;
}


//长按切换 红外白光模式/退出菜单
uint8_t KEY_FUNC_LONG_PRESS_START_Handler(void *btn)
{
	static _Bool ClearOsdScreen;
	uint8_t ClearScreenQueue;
	bool state;


 if(MenuLevel == _MainMenu) //菜单级别
	{
		switch(OsdLight_Mode)
		{
			case _Daylight:
				//切红外把所有白光要展示的模块清遍
				StopLoadingContinueTimer();
			
				EraseDaylightOsdShow();
				//Uart3Send((uint8_t*)Enter_click,10);
				Set_Osd_LightMode(_Infrared);
				OsdLight_Mode = _Infrared;	//红外
			
		    	EraseLoading();//清洗描线位置显示内容，防止速切时候，图形粘贴现象

    			Infrared_AmplifierReduce_OsdShow(IR_AmplifierReduce_Date);
				InfraredOsdShow();
				//放大倍数
				IR_ZoomMCheck(IR_ZOOM_Cmd);
#if ChengDu 

				Uart3Send(IR_DNR_Cmd,MyStrlen(IR_ZOOM_Cmd));
#elif BT656
			    Uart3Send(IR_OutDoor_OFF_Cmd,MyStrlen(IR_OutDoor_OFF_Cmd));
			
			    Uart3Send(IR_Hot_Point_OFF_Cmd,MyStrlen(IR_Hot_Point_OFF_Cmd));

			
#endif
		

				OsdRefresh_Family[_IR_Zoom].Refresh_Flag = Refresh_yes;
				SetIRmode();
			
				switch(OsdRefresh_Family[_IR_Polar].Data)
				{
						case _WhiteHot:
							Osd_Infrared_ColorMode = _WhiteHot;
							Uart3Send(IR_Polar_WHot_Cmd,MyStrlen(IR_Polar_WHot_Cmd));
							break;
						case _BlackHot:
							Osd_Infrared_ColorMode = _BlackHot;
							Uart3Send(IR_Polar_BHot_Cmd,MyStrlen(IR_Polar_BHot_Cmd));
							break;
#if ChengDu 							
						case _Rainbow:
							Osd_Infrared_ColorMode = _Rainbow;
							//关闭条纹降噪
//								IR_BT656_StripeDenoising_Cmd[10] = 0x00;
//								IR_SumCheck(IR_BT656_StripeDenoising_Cmd);
//								Uart3Send(IR_BT656_StripeDenoising_Cmd,MyStrlen(IR_BT656_StripeDenoising_Cmd));
							//开启rainbow模式
							Uart3Send(IR_Polar_RainBow_Cmd,MyStrlen(IR_Polar_RainBow_Cmd));
							break;
#elif BT656
						
							
#endif
						case _Iron:
							Osd_Infrared_ColorMode = _Iron;
							Uart3Send(IR_Polar_Iron_Cmd,MyStrlen(IR_Polar_Iron_Cmd));
							break;
						case _GreenHot:
							Osd_Infrared_ColorMode = _GreenHot;
							Uart3Send(IR_Polar_Green_Cmd,MyStrlen(IR_Polar_Green_Cmd));
							break;
						default:
							break;					
				}
			    Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
								
				OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
				break;
				
			case _Infrared:
				//切白光把所有红外要展示的模块清遍
				EraseInfraredOsdShow();
				Set_Osd_LightMode(_Daylight);
				OsdLight_Mode = _Daylight;	//白光
				DaylightOsdShow();
                SetVLmode();
				OsdRefresh_Family[_VL_Mode].Data = _Day;
			
				VL_AmplifierReduce_Date = _VL_AmplifierReduce_1;
				Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
				xQueueSend(Zoom_QueueHandle,&state,0);
//			    OsdRefresh_Family[_AmplifierReduce].Refresh_Flag = Refresh_yes;

				switch(OsdRefresh_Family[_VL_Mode].Data)
				{
						case _Auto:
							Osd_Daylight_ColorMode = _Auto;
							//Uart6Send(VL_Mode_Defog_OFF_Cmd,MyStrlen(VL_Mode_Defog_OFF_Cmd));
							//Uart6Send(VL_Mode_Auto_Cmd,MyStrlen(VL_Mode_Auto_Cmd));
							break;
						case _Day:
							Osd_Daylight_ColorMode = _Day;
							//Uart6Send(VL_Mode_Defog_OFF_Cmd,MyStrlen(VL_Mode_Defog_OFF_Cmd));
							//Uart6Send(VL_Mode_Day_Cmd,MyStrlen(VL_Mode_Day_Cmd));
							break;
						case _Defog_Low:
							Osd_Daylight_ColorMode = _Defog_Low;
							//Uart6Send(VL_Mode_Defog_ON_Cmd,MyStrlen(VL_Mode_Defog_ON_Cmd));
							//Uart6Send(VL_Mode_Defog_Low_Cmd,MyStrlen(VL_Mode_Defog_Low_Cmd));
							break;
						case _Defog_Mid:
							Osd_Daylight_ColorMode = _Defog_Mid;
							//Uart6Send(VL_Mode_Defog_ON_Cmd,MyStrlen(VL_Mode_Defog_ON_Cmd));
							//Uart6Send(VL_Mode_Defog_Mid_Cmd,MyStrlen(VL_Mode_Defog_Mid_Cmd));
							break;
						case _Defog_Hig:
							Osd_Daylight_ColorMode = _Defog_Hig;
							//Uart6Send(VL_Mode_Defog_ON_Cmd,MyStrlen(VL_Mode_Defog_ON_Cmd));
							//Uart6Send(VL_Mode_Defog_Hig_Cmd,MyStrlen(VL_Mode_Defog_Hig_Cmd));
							break;
						case _Night:
							Osd_Daylight_ColorMode = _Night;
							//Uart6Send(VL_Mode_Defog_OFF_Cmd,MyStrlen(VL_Mode_Defog_OFF_Cmd));
							//Uart6Send(VL_Mode_Night_Cmd,MyStrlen(VL_Mode_Night_Cmd));
							break;
						default:
							Osd_Daylight_ColorMode = _Auto;
							OsdRefresh_Family[_VL_Mode].Data = Osd_Daylight_ColorMode;
							//Uart6Send(VL_Mode_Defog_OFF_Cmd,MyStrlen(VL_Mode_Defog_OFF_Cmd));
							//Uart6Send(VL_Mode_Auto_Cmd,MyStrlen(VL_Mode_Auto_Cmd));
							break;					
				}
						
				Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);

				ShowLoading();

				OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
				
	//					OsdRefresh_Family[_VL_Mode].Refresh_Flag = Refresh_yes;
				break;
								
			default	:
				break;
		}
	}
	return 1;
}



uint8_t KEY_FUNC_LONG_PRESS_HOLD_Handler(void *btn)
{
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}
    // do something...
		return 1;
}

uint8_t IR_Zoom;


// KEY_Up 按键回调函数
uint8_t KEY_UP_SINGLE_Click_Handler(void *btn)
{

		if(MenuLevel == _MainMenu) //菜单级别
		{
			if(OsdLight_Mode == _Infrared) //红外模式下有效
			{
				
#if Motor_Flag
				MotorRun_Mode = _Foreward;
				MotorForwardReverse_OsdShow(MotorRun_Mode);
				OsdRefresh_Family[_ForwardReverse].Refresh_Flag = Refresh_yes;
				xQueueSend(ForewardReverse_QueueHandle,&MotorRun_Mode,0);//
#endif

			}
		}
		return 1;
}


uint8_t KEY_UP_DOUBLE_Click_Handler(void *btn)
{	
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}
    // do something...
		return 1;
}
uint8_t KEY_UP_LONG_PRESS_START_Handler(void *btn)
{
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}
		
		if(MenuLevel == _MainMenu) //菜单级别
		{
			if(OsdLight_Mode == _Infrared) //红外模式下有效
			{
#if Motor_Flag
				MotorRun_Mode = _Foreward;
				MotorForwardReverse_OsdShow(MotorRun_Mode);
				OsdRefresh_Family[_ForwardReverse].Refresh_Flag = Refresh_yes;
				xQueueSend(ForewardReverse_QueueHandle,&MotorRun_Mode,0);//
#endif
			}
			
			
			return 1;
		}
    // do something...
		return 1;

}

uint8_t KEY_UP_LONG_PRESS_HOLD_Handler(void *btn)
{
		static uint16_t num = 0;
		bool state;
	
		if(MenuLevel == _MainMenu) //菜单级别
		{
			if(OsdLight_Mode == _Infrared) //红外模式下有效
			{
#if Motor_Flag
				MotorRun_Mode = _Foreward;
				MotorForwardReverse_OsdShow(MotorRun_Mode);
				OsdRefresh_Family[_ForwardReverse].Refresh_Flag = Refresh_yes;
				xQueueSend(ForewardReverse_QueueHandle,&MotorRun_Mode,0);//
#endif
			}

			return 1;
		}
	
    // do something...
		return 1;
}

uint8_t KEY_UP_PRESS_UP(void *btn)
{
		if(MenuLevel == _MainMenu) //菜单级别
		{
#if Motor_Flag
			MotorRun_Mode = _MotorStop;
			MotorForwardReverse_OsdShow(_MotorStop);
			OsdRefresh_Family[_ForwardReverse].Refresh_Flag = Refresh_yes;
			xQueueSend(ForewardReverse_QueueHandle,&MotorRun_Mode,0);//
#endif
			return 1;
		}
		
		//单击无效
		if(KEY_Up_LONG_PRESS_HOLD_Flag == false)
		{
			return 0;
		}
	
    // do something...
		return 1;
}




// KEY_Down 按键回调函数
uint8_t KEY_DOWN_SINGLE_Click_Handler(void *btn)
{
	bool state;
	
	if(MenuLevel == _MainMenu) //菜单级别
		{
			if(OsdLight_Mode == _Infrared) //红外模式下有效
			{
#if Motor_Flag
				MotorRun_Mode = _Reverse;
				MotorForwardReverse_OsdShow(MotorRun_Mode);
				OsdRefresh_Family[_ForwardReverse].Refresh_Flag = Refresh_yes;
				xQueueSend(ForewardReverse_QueueHandle,&MotorRun_Mode,0);//
#endif
			}
			
			return 1;
		}
		
		return 1;
}



uint8_t KEY_DOWN_DOUBLE_Click_Handler(void *btn)
{
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}	
    // do something...
		return 1;
}



uint8_t KEY_DOWN_LONG_PRESS_START_Handler(void *btn)
{

		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}
		
		if(MenuLevel == _MainMenu) //菜单级别
		{
			if(OsdLight_Mode == _Infrared) //红外模式下有效
			{
				
#if Motor_Flag
				MotorRun_Mode = _Reverse;
				MotorForwardReverse_OsdShow(MotorRun_Mode);
				OsdRefresh_Family[_ForwardReverse].Refresh_Flag = Refresh_yes;
				xQueueSend(ForewardReverse_QueueHandle,&MotorRun_Mode,0);//
#endif
			}
			
			return 1;
		}
    // do something...
		return 1;

}


uint8_t KEY_DOWN_LONG_PRESS_HOLD_Handler(void *btn)
{
		static uint16_t num = 0;
		bool state;
	
	if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}
		
		if(MenuLevel == _MainMenu) //菜单级别
		{
			if(OsdLight_Mode == _Infrared) //红外模式下有效
			{
#if Motor_Flag
				MotorRun_Mode = _Reverse;
				MotorForwardReverse_OsdShow(MotorRun_Mode);
				OsdRefresh_Family[_ForwardReverse].Refresh_Flag = Refresh_yes;
				xQueueSend(ForewardReverse_QueueHandle,&MotorRun_Mode,0);//
#endif
			}
			else if(OsdLight_Mode == _Daylight)
			{
			
			}
		}
		
		
    // do something...
		return 1;
}

uint8_t KEY_DOWN_PRESS_UP(void *btn)
{
		if(MenuLevel == _MainMenu) //菜单级别
		{
#if Motor_Flag
			MotorRun_Mode = _MotorStop;
			MotorForwardReverse_OsdShow(_MotorStop);
			OsdRefresh_Family[_ForwardReverse].Refresh_Flag = Refresh_yes;
			xQueueSend(ForewardReverse_QueueHandle,&MotorRun_Mode,0);//
#endif
			return 1;
		}
		if(KEY_Down_LONG_PRESS_HOLD_Flag == false)
		{
			return 0;
		}
	
    // do something...
		return 1;
}


//////////////////////////

// KEY_Up 按键回调函数
uint8_t KEY_Laser_SINGLE_Click_Handler(void *btn)
{
	uint8_t ClearScreenQueue;
	
	
		bool state;
	
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}

		if(OsdLight_Mode == _Daylight) 
		{
			StartDistanceTimer();
			VL_Zoom_DZoomSet(10);
			VL_AmplifierReduce_Date = _VL_AmplifierReduce_10;
			Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
			xQueueSend(Zoom_QueueHandle,&state,0);
		}
		if(Flag_LsserON ==false) //启动
		{
					//白光模式下放大倍数调到10倍数

		
			StartDistanceTimer();
		
			Flag_LsserON = true;
			
			LaserPowerON();
			OsdRefresh_Family[_LaserFlag].Module_addr[0] = osd_Icon_Laser_1;
			OsdRefresh_Family[_LaserFlag].Module_addr[1] = osd_Icon_Laser_2;
			OsdRefresh_Family[_LaserFlag].Module_addr[2] = '\r';
			OsdRefresh_Family[_LaserFlag].Refresh_Flag = Refresh_yes;
			return 2;
		}
		


		
		//测距
		DistanceMesureOne();
		//闪烁
		xQueueSend(Laser_QueueHandle,&ClearScreenQueue,0); //激光图标闪烁
		OsdRefresh_Family[_LaserFlag].Refresh_Flag = Refresh_yes;
		return 1;
}

uint8_t KEY_Laser_DOUBLE_Click_Handler(void *btn)
{	
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}
    // do something...
		return 1;
}
uint8_t KEY_Laser_LONG_PRESS_START_Handler(void *btn)
{
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}
    // do something...
		LaserPowerOFF();
		OsdRefresh_Family[_LaserFlag].Module_addr[0] = osd_NONE;
		OsdRefresh_Family[_LaserFlag].Module_addr[1] = osd_NONE;
		OsdRefresh_Family[_LaserFlag].Module_addr[2] = '\r';
		OsdRefresh_Family[_LaserFlag].Refresh_Flag = Refresh_yes;
		
		OsdRefresh_Family[_Distance].Module_addr[0] = osd_NONE;
		OsdRefresh_Family[_Distance].Module_addr[1] = osd_NONE;
		OsdRefresh_Family[_Distance].Module_addr[2] = osd_NONE;
		OsdRefresh_Family[_Distance].Module_addr[3] = osd_NONE;
		OsdRefresh_Family[_Distance].Module_addr[4] = osd_NONE;
		OsdRefresh_Family[_Distance].Refresh_Flag = Refresh_yes;
		Flag_LsserON = false;
		return 1;

}
uint8_t KEY_Laser_LONG_PRESS_HOLD_Handler(void *btn)
{
		static uint16_t num = 0;
		bool state;
	
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}

		return 1;
}

uint8_t KEY_Laser_PRESS_UP(void *btn)
{
	bool state;
	
		
		return 1;
}

/************二级菜单***************/
// JOY_Down 按键回调函数
uint8_t JOY_Down_SINGLE_Click_Handler(void *btn)
{
	bool state;
	
	 if(MenuLevel == _ConfigMenu)
		{
			ConfigMenuPra+=2;
			CursorDown(&ConfigMenuPra);
			return 1;
		}
	 else if(MenuLevel == _MainMenu)
		{
			if(OsdLight_Mode == _Infrared) 
			{
	#if ChengDu			
					if(IR_AmplifierReduce_Date > _IR_AmplifierReduce_1)
					{
						IR_AmplifierReduce_Date -= 2;
						Infrared_AmplifierReduce_OsdShow(IR_AmplifierReduce_Date);
						if(IR_AmplifierReduce_Date == 0)//发的倍数不能为0
							IR_ZOOM_Cmd[10] = 1;
						else
						IR_ZOOM_Cmd[10] = IR_AmplifierReduce_Date;
						
						IR_ZoomMCheck(IR_ZOOM_Cmd);
						Uart3Send(IR_ZOOM_Cmd,MyStrlen(IR_ZOOM_Cmd));
						OsdRefresh_Family[_IR_Zoom].Refresh_Flag = Refresh_yes;
					}
	#elif BT656 
				
	#endif			
			}
			else if(OsdLight_Mode == _Daylight)
			{
	#if VL_MC_105Q

				if(VL_AmplifierReduce_Date >= 2) //放大停止
				{
					
					VL_AmplifierReduce_Date --;
					if(VL_AmplifierReduce_Date== 1)
					{
						Daylight_AmplifierReduce_OsdShow(0);
						VL_Zoom_DZoomSet(1);
						xQueueSend(Zoom_QueueHandle,&state,0);
						return 1;
					}

					MotorStop_Source = _No_Stop;
					Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
					VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);
					xQueueSend(Zoom_QueueHandle,&state,0);

				}
	#endif

	#if VL_YT_3578_HD

				if(VL_AmplifierReduce_Date >= 2) //放大停止
				{
					
					VL_AmplifierReduce_Date --;
					if(VL_AmplifierReduce_Date == 1)
					{
						Daylight_AmplifierReduce_OsdShow(0);
						VL_Zoom_DZoomSet(1);
						xQueueSend(Zoom_QueueHandle,&state,0);
						return 1;
					}

					
					Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
					VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);
					xQueueSend(Zoom_QueueHandle,&state,0);

				}
	#endif
			}
				return 1;
		}
		return 1;
}
uint8_t JOY_Down_DOUBLE_Click_Handler(void *btn)
{
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}	
    // do something...
		return 1;
}

uint8_t JOY_Down_LONG_PRESS_START_Handler(void *btn)
{
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}
    // do something...
		return 1;

}

uint8_t JOY_Down_LONG_PRESS_HOLD_Handler(void *btn)
{
 		static uint16_t num = 0;
		bool state;
	
	if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}
		
		if(MenuLevel == _MainMenu) //菜单级别
		{
			if(OsdLight_Mode == _Infrared) //红外模式下有效
			{
				KEY_Down_LONG_PRESS_HOLD_Flag = true;
				num++;
				if(num>100)
				{
					num = 0;
	#if ChengDu			
					if(IR_AmplifierReduce_Date > 1)
					{
						IR_AmplifierReduce_Date -= 2;
						Infrared_AmplifierReduce_OsdShow(IR_AmplifierReduce_Date);
						if(IR_AmplifierReduce_Date == 0)//发的倍数不能为0
							IR_ZOOM_Cmd[10] = 1;
						else
						IR_ZOOM_Cmd[10] = IR_AmplifierReduce_Date;
						
						IR_ZoomMCheck(IR_ZOOM_Cmd);
						Uart3Send(IR_ZOOM_Cmd,MyStrlen(IR_ZOOM_Cmd));
						OsdRefresh_Family[_IR_Zoom].Refresh_Flag = Refresh_yes;
					}
	#elif BT656 
				
	#endif		
				}
				
			}
			else if(OsdLight_Mode == _Daylight)
			{
				KEY_Down_LONG_PRESS_HOLD_Flag = true;
				num++;
				if(num>300)
				{
					num = 0;
#if VL_MC_105Q

					if(VL_AmplifierReduce_Date >= 2) //放大停止
					{
						
						VL_AmplifierReduce_Date --;
						if(VL_AmplifierReduce_Date== 1)
						{
							Daylight_AmplifierReduce_OsdShow(0);
							VL_Zoom_DZoomSet(1);
							xQueueSend(Zoom_QueueHandle,&state,0);
							return 1;
						}

						MotorStop_Source = _No_Stop;
						Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
						VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);
						xQueueSend(Zoom_QueueHandle,&state,0);

					}

#elif VL_YT_3578_HD

					if(VL_AmplifierReduce_Date >= _VL_AmplifierReduce_2)
					{
							VL_AmplifierReduce_Date --;
							Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
						  VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);
							
							state = true;
							xQueueSend(Zoom_QueueHandle,&state,0);
					}
					else
					{
					  VL_AmplifierReduce_Date = _VL_AmplifierReduce_0;
						Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
						VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);

						state = true;
						xQueueSend(Zoom_QueueHandle,&state,0);
					}
#endif		
			
			   }
			return 1;
		
		
			}
		}
		
	return 1;
}

uint8_t JOY_Down_PRESS_UP(void *btn)
{
	bool state;
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}
		if(OsdLight_Mode != _Daylight) 
		{
			return 2;
		}
		
		//单击无效
		if(KEY_Down_LONG_PRESS_HOLD_Flag == false)
		{
			return 0;
		}

		return 1;
}

uint8_t JOY_Up_SINGLE_Click_Handler(void *btn)
{
	bool state;
	if(MenuLevel == _ConfigMenu)
	{
		ConfigMenuPra-=2;
		CursorUp(&ConfigMenuPra);
		return 1;
	}
	else if(MenuLevel == _MainMenu)
	{

		if(OsdLight_Mode == _Daylight)
		{
#if VL_MC_105Q

			if(VL_AmplifierReduce_Date < _VL_AmplifierReduce_16)
			{
					VL_AmplifierReduce_Date ++;
					Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
					VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);
					
					state = true;
					xQueueSend(Zoom_QueueHandle,&state,0);
			}
			else
			{
				VL_AmplifierReduce_Date = _VL_AmplifierReduce_16;
				Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
				VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);
				
				state = true;
				xQueueSend(Zoom_QueueHandle,&state,0);
			}
			
#endif
#if VL_YT_3578_HD

			if(VL_AmplifierReduce_Date < _VL_AmplifierReduce_16)
			{
				VL_AmplifierReduce_Date ++;
				Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
				VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);
				
				state = true;
				xQueueSend(Zoom_QueueHandle,&state,0);
			}
			else
			{
			    VL_AmplifierReduce_Date = _VL_AmplifierReduce_1;
				Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
				VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);

				state = true;
				xQueueSend(Zoom_QueueHandle,&state,0);
			}
#endif
			
		}
		else if(OsdLight_Mode == _Infrared)
		{
#if ChengDu			
				 if(IR_AmplifierReduce_Date < _IR_AmplifierReduce_8)
				{
					if(IR_AmplifierReduce_Date == 1)
						IR_AmplifierReduce_Date = 0;
						
					IR_AmplifierReduce_Date += 2;
					Infrared_AmplifierReduce_OsdShow(IR_AmplifierReduce_Date);
					
					OsdRefresh_Family[_IR_Zoom].Refresh_Flag = Refresh_yes;
					IR_ZOOM_Cmd[10] = IR_AmplifierReduce_Date;
					IR_ZoomMCheck(IR_ZOOM_Cmd);
					Uart3Send(IR_ZOOM_Cmd,MyStrlen(IR_ZOOM_Cmd));
				}
	
#elif BT656 

#endif			
		}
			
			
			
			return 1;
		}
		
		return 1;
		
}
uint8_t JOY_Up_DOUBLE_Click_Handler(void *btn)
{
		if(MenuLevel == _MainMenu) //菜单级别
		{
			return 1;
		}
	
    // do something...
		return 1;
}

uint8_t JOY_Up_LONG_PRESS_START_Handler(void *btn)
{
		if(MenuLevel == _MainMenu) //菜单级别
		{
			return 1;
		}
	
    // do something...
		return 1;

}

uint8_t JOY_Up_LONG_PRESS_HOLD_Handler(void *btn)
{
	static uint16_t num = 0;
	bool state;
		if(MenuLevel == _MainMenu) //菜单级别
		{
		  KEY_Up_LONG_PRESS_HOLD_Flag = true;
		   if(OsdLight_Mode == _Daylight)
			{
				
				num++;
				if(num>300)
				{
					num = 0;
#if VL_MC_105Q
//					VL_AmplifierReduce_Date++;
//					if(VL_AmplifierReduce_Date >=_VL_AmplifierReduce_16)
//					{
//						VL_AmplifierReduce_Date = _VL_AmplifierReduce_16;
//						//AmplifierReduce_Date = _AmplifierReduce_1;
//		//				AmplifierReduce_OsdShow(16);
//		//				xQueueSend(Zoom_QueueHandle,&state,0);
//					}
//					else
//					{

//						VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);
//						Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
//						xQueueSend(Zoom_QueueHandle,&state,0);
//					}
					
				if(VL_AmplifierReduce_Date < _VL_AmplifierReduce_16)
					{
							VL_AmplifierReduce_Date ++;
							Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
						  VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);
							
							state = true;
							xQueueSend(Zoom_QueueHandle,&state,0);
					}
					else
					{
					  VL_AmplifierReduce_Date = _VL_AmplifierReduce_16;
						Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
						VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);

						state = true;
						xQueueSend(Zoom_QueueHandle,&state,0);
					}
					
#elif VL_YT_3578_HD
			
					if(VL_AmplifierReduce_Date < _VL_AmplifierReduce_16)
					{
							VL_AmplifierReduce_Date ++;
							Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
						  VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);
							
							state = true;
							xQueueSend(Zoom_QueueHandle,&state,0);
					}
					else
					{
					  VL_AmplifierReduce_Date = _VL_AmplifierReduce_16;
						Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
						VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);

						state = true;
						xQueueSend(Zoom_QueueHandle,&state,0);
					}
			
#endif			
				}
			}
			else if(OsdLight_Mode == _Infrared)
			{
				num++;
				if(num>100)
				{
					num = 0;
					
#if ChengDu			
				if(IR_AmplifierReduce_Date < _IR_AmplifierReduce_8)
				{
					if(IR_AmplifierReduce_Date == 1)
						IR_AmplifierReduce_Date = 0;
						
					IR_AmplifierReduce_Date += 2;
					Infrared_AmplifierReduce_OsdShow(IR_AmplifierReduce_Date);
					
					OsdRefresh_Family[_IR_Zoom].Refresh_Flag = Refresh_yes;
					IR_ZOOM_Cmd[10] = IR_AmplifierReduce_Date;
					IR_ZoomMCheck(IR_ZOOM_Cmd);
					Uart3Send(IR_ZOOM_Cmd,MyStrlen(IR_ZOOM_Cmd));
				}
				else
				{
					IR_AmplifierReduce_Date = _IR_AmplifierReduce_8;
					Infrared_AmplifierReduce_OsdShow(IR_AmplifierReduce_Date);
					
					OsdRefresh_Family[_IR_Zoom].Refresh_Flag = Refresh_yes;
					IR_ZOOM_Cmd[10] = IR_AmplifierReduce_Date;
					IR_ZoomMCheck(IR_ZOOM_Cmd);
					Uart3Send(IR_ZOOM_Cmd,MyStrlen(IR_ZOOM_Cmd));
				}	
		
#elif BT656 

#endif	
				}	
				
			
			
			}
			return 1;
		}
		
		
		// do something...
			return 1;
}

uint8_t JOY_Up_PRESS_UP(void *btn)
{	
		bool state;
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}
		
		if(OsdLight_Mode != _Daylight) 
		{
			return 2;
		}
		
		//单击无效
		if(KEY_Up_LONG_PRESS_HOLD_Flag == false)
		{
			return 0;
		}
 
		return 1;
	
    // do something...
		return 1;
}

// KEY_Left 按键回调函数
uint8_t JOY_Left_SINGLE_Click_Handler(void *btn)
{
#if Control_Num_Blink_Flag				

		if( MenuLevel == _ParameterSet) //菜单级别
		{
			CursorLeft(&ConfigMenuPra);
			
			return 1;
		}
#else
	CursorLeft(&ConfigMenuPra);
#endif
		return 1;
}
uint8_t JOY_Left_DOUBLE_Click_Handler(void *btn)
{
		if(MenuLevel == _MainMenu) //菜单级别
		{
			return 1;
		}
		
    // do something...
		return 1;
}

uint8_t JOY_Left_LONG_PRESS_START_Handler(void *btn)
{
		if(MenuLevel == _MainMenu) //菜单级别
		{
			return 1;
		}
		
    // do something...
		return 1;

}

uint8_t JOY_Left_LONG_PRESS_HOLD_Handler(void *btn)
{
		if(MenuLevel == _MainMenu) //菜单级别
		{
			return 1;
		}
		
    // do something...
		return 1;
}

// KEY_Right 按键回调函数
uint8_t JOY_Right_SINGLE_Click_Handler(void *btn)
{
	//////////
#if Control_Num_Blink_Flag				

		if(MenuLevel == _ParameterSet) //菜单级别
		{
			CursorRight(&ConfigMenuPra);
			return 1;
		}
#else
			CursorRight(&ConfigMenuPra);

#endif
	
		return 1;
}
uint8_t JOY_Right_DOUBLE_Click_Handler(void *btn)
{
		if(MenuLevel == _MainMenu) //菜单级别
		{
			return 1;
		}

    // do something...
		return 1;
}

uint8_t JOY_Right_LONG_PRESS_START_Handler(void *btn)
{
		if(MenuLevel == _MainMenu) //菜单级别
		{
			return 1;
		}
		
    // do something...
		return 1;

}

uint8_t JOY_Right_LONG_PRESS_HOLD_Handler(void *btn)
{
		if(MenuLevel == _MainMenu) //菜单级别
		{
			return 1;
		}
	
    // do something...

		return 1;
}

// JOY_Center 按键回调函数
uint8_t JOY_Center_SINGLE_Click_Handler(void *btn)
{
	uint8_t ClearScreenQueue;
    // do something...
		switch(MenuLevel)
		{
			case _MainMenu://进入配置菜单首页
				MenuLevel = _ConfigMenu;
				if(OsdLight_Mode == _Infrared)
				{
#if WiFi_Flag					
					OsdRefresh_Family[_IR_Wifi].Refresh_Flag = Refresh_yes;
#endif	
					OsdRefresh_Family[_IR_PR].Refresh_Flag = Refresh_yes;
					ConfigMenu_IR_OsdShowON();
					ConfigMenuPra = _IR_Brightness;//初始化配置菜单状态
				}
				else if(OsdLight_Mode == _Daylight)
				{
#if WiFi_Flag					
					OsdRefresh_Family[_VL_Wifi].Refresh_Flag = Refresh_yes;
#endif	
					OsdRefresh_Family[_VL_PR].Refresh_Flag = Refresh_yes;
					ConfigMenu_VL_OsdShowON();
					ConfigMenuPra = _VL_Brightness;//初始化配置菜单状态
				}
				break;
				
#if Control_Num_Blink_Flag				
			case _ConfigMenu:	
					MenuLevel = _ParameterSet;
				break;
			
			case _ParameterSet:
				MenuLevel = _ConfigMenu;
				break;
#else
			case _ConfigMenu:	
				//if(ConfigMenuPra == _IR_Exit || ConfigMenuPra == _VL_Exit ) //退出配置菜单
				//{
					
					ClearScreenQueue = 0;//只清屏
					xQueueSend(Osd_ClearScreen_QueueHandle,&ClearScreenQueue,0);
					CursorReset_OsdShow();//擦除各个位置的光标
					ConfigMenu_OsdShowOFF();//擦除配置界面
					MenuLevel = _MainMenu;
				//}
#endif
			default:
				break;
		}
		
		return 1;
}
uint8_t JOY_Center_DOUBLE_Click_Handler(void *btn)
{
		if(MenuLevel == _MainMenu) //菜单级别
		{
			return 1;
		}
		
    // do something...
		return 1;
}

uint8_t JOY_Center_LONG_PRESS_START_Handler(void *btn)
{
    uint8_t ClearScreenQueue;
	
	if(MenuLevel != _MainMenu) //菜单级别
	{
		MenuLevel = _MainMenu;
		ClearScreenQueue = 0;//只清屏
		xQueueSend(Osd_ClearScreen_QueueHandle,&ClearScreenQueue,0);
		CursorReset_OsdShow();//擦除各个位置的光标
		ConfigMenu_OsdShowOFF();//擦除配置界面
		return 1;
	}
		
    // do something...
		return 1;

}


uint8_t JOY_Center_LONG_PRESS_HOLD_Handler(void *btn)
{
	
		if(MenuLevel == _MainMenu) //菜单级别
		{
			return 1;
		}
		
    // do something...
		return 1;
}
#elif VA_675B75_MF

void ButtonInit(void)
{
	
	//一级菜单
	key_io_init();

	/**********************************按键初始化***************************************/
	button_init(&KEY_Menu, read_key_level, KEY_ON, KEY_Menu_id); 	// PB8
	button_init(&KEY_Func, read_key_level, KEY_ON, KEY_Func_id); 	//PB9
	button_init(&KEY_Up, read_key_level, KEY_ON, KEY_Up_id);			//PC13
	button_init(&KEY_Down, read_key_level, KEY_ON, KEY_Down_id);	//PC14
	button_init(&KEY_Laser, read_key_level, KEY_ON, KEY_Laser_id);	//PC14

	button_attach(&KEY_Menu, SINGLE_CLICK, KEY_MENU_SINGLE_Click_Handler);
	button_attach(&KEY_Menu, DOUBLE_CLICK, KEY_MENU_DOUBLE_Click_Handler);
	button_attach(&KEY_Menu, LONG_PRESS_START, KEY_MENU_LONG_PRESS_START_Handler);
	button_attach(&KEY_Menu, LONG_PRESS_HOLD, KEY_MENU_LONG_PRESS_HOLD_Handler);

	button_attach(&KEY_Func, SINGLE_CLICK, KEY_FUNC_SINGLE_Click_Handler);
	button_attach(&KEY_Func, DOUBLE_CLICK, KEY_FUNC_DOUBLE_Click_Handler);
	button_attach(&KEY_Func, LONG_PRESS_START, KEY_FUNC_LONG_PRESS_START_Handler);
	button_attach(&KEY_Func, LONG_PRESS_HOLD, KEY_FUNC_LONG_PRESS_HOLD_Handler);

	button_attach(&KEY_Up, SINGLE_CLICK, KEY_UP_SINGLE_Click_Handler);
	button_attach(&KEY_Up, DOUBLE_CLICK, KEY_UP_DOUBLE_Click_Handler);
	button_attach(&KEY_Up, LONG_PRESS_START, KEY_UP_LONG_PRESS_START_Handler);
	button_attach(&KEY_Up, LONG_PRESS_HOLD, KEY_UP_LONG_PRESS_HOLD_Handler);
	button_attach(&KEY_Up, PRESS_UP, KEY_UP_PRESS_UP);

	button_attach(&KEY_Down, SINGLE_CLICK, KEY_DOWN_SINGLE_Click_Handler);
	button_attach(&KEY_Down, DOUBLE_CLICK, KEY_DOWN_DOUBLE_Click_Handler);
	button_attach(&KEY_Down, LONG_PRESS_START, KEY_DOWN_LONG_PRESS_START_Handler);
	button_attach(&KEY_Down, LONG_PRESS_HOLD, KEY_DOWN_LONG_PRESS_HOLD_Handler);
	button_attach(&KEY_Down, PRESS_UP, KEY_DOWN_PRESS_UP);

	button_attach(&KEY_Laser, SINGLE_CLICK, KEY_Laser_SINGLE_Click_Handler);
	button_attach(&KEY_Laser, DOUBLE_CLICK, KEY_Laser_DOUBLE_Click_Handler);
	button_attach(&KEY_Laser, LONG_PRESS_START, KEY_Laser_LONG_PRESS_START_Handler);
	button_attach(&KEY_Laser, LONG_PRESS_HOLD, KEY_Laser_LONG_PRESS_HOLD_Handler);
	button_attach(&KEY_Laser, PRESS_UP, KEY_Laser_PRESS_UP);

	button_start(&KEY_Menu);
	button_start(&KEY_Func);
	button_start(&KEY_Up);
	button_start(&KEY_Down);
	button_start(&KEY_Laser);


	
}

// KEY_Menu 按键回调函数 短按切换拍照或拍照
uint8_t KEY_MENU_SINGLE_Click_Handler(void *btn)
{
	_OsdRun_Mode Photo_quen;
	
	if(Flag_PhotoRecordeEnable == FALSE) //判断启动
		{
			return 1;
		}
		
	if(MenuLevel != _MainMenu) //菜单级别
		{
			return 1;
		}
		
    // do something...
		switch(OsdLight_Mode)
		{
			case _Daylight:
				if(OsdRun_Mode == _RecordMode) //录像
				{
					Rec_OFF();//结束录像
					OsdRun_Mode = _PhotoMode;//切换拍照模式
					Set_Osd_PhotoRecord(OsdRun_Mode);
					OsdRefresh_Family[_PhotoRecord].Refresh_Flag = Refresh_yes;
					
				}
				else if(OsdRun_Mode == _PhotoMode) //单击拍照 闪烁
				{
					//OsdRun_Mode = _PhotoMode;//切拍照
					Set_Osd_PhotoRecord(OsdRun_Mode);
					OsdRefresh_Family[_PhotoRecord].Refresh_Flag = Refresh_yes;
					Photo_quen = _PhotoMode;
					TakePhoto(); //拍照
					xQueueSend(Photo_QueueHandle,&Photo_quen,0);
				}
				break;
				
			case _Infrared:
				if(OsdRun_Mode == _RecordMode) //录像
				{
					Rec_OFF();//结束录像
					OsdRun_Mode = _PhotoMode;//切换拍照模式
					Set_Osd_PhotoRecord(OsdRun_Mode);
					OsdRefresh_Family[_PhotoRecord].Refresh_Flag = Refresh_yes;
					
				}
				else if(OsdRun_Mode == _PhotoMode) //单击拍照 闪烁
				{
					//OsdRun_Mode = _PhotoMode;//切拍照
					Set_Osd_PhotoRecord(OsdRun_Mode);
					OsdRefresh_Family[_PhotoRecord].Refresh_Flag = Refresh_yes;
					Photo_quen = _PhotoMode;
					TakePhoto(); //拍照
					xQueueSend(Photo_QueueHandle,&Photo_quen,0);
				}
				break;
				
			default :
				break;
			}
		
		return 1;
}

uint8_t KEY_MENU_DOUBLE_Click_Handler(void *btn)
{
	if(MenuLevel != _MainMenu) //菜单级别
		{
			return 1;
		}
    // do something...
		return 1;
}

//长按 切换录像
uint8_t KEY_MENU_LONG_PRESS_START_Handler(void *btn)
{
		if(MenuLevel != _MainMenu) //菜单级别
		{
			return 1;
		}
		
	if(Flag_PhotoRecordeEnable == FALSE) //判断启动
		{
			Flag_PhotoRecordeEnable = TRUE;
			
			//默认拍照模式
			OsdRun_Mode = _PhotoMode;//切拍照
			Set_Osd_PhotoRecord(OsdRun_Mode);
			OsdRefresh_Family[_PhotoRecord].Refresh_Flag = Refresh_yes;
			
			OsdRefresh_Family[_VL_PR].Data = 1; //拍照录像模式启动
			//DecToHexToAscii(OsdRefresh_Family[_PR].Data, 0, OsdRefresh_Family[_PR].Module_addr, 1);
			OsdRefresh_Family[_VL_PR].Module_addr[0] = osd_ON;
			OsdRefresh_Family[_VL_PR].Module_addr[1] = osd_NONE;
			OsdRefresh_Family[_VL_PR].Module_addr[2] = '\r';
			
			OsdRefresh_Family[_IR_PR].Data = 1; //拍照录像模式启动
			//DecToHexToAscii(OsdRefresh_Family[_PR].Data, 0, OsdRefresh_Family[_PR].Module_addr, 1);
			OsdRefresh_Family[_IR_PR].Module_addr[0] = osd_ON;
			OsdRefresh_Family[_IR_PR].Module_addr[1] = osd_NONE;
			OsdRefresh_Family[_IR_PR].Module_addr[2] = '\r';
			return 1;
		}
		
	switch(OsdLight_Mode)
	{
		case _Daylight:

			OsdRun_Mode = _RecordMode;//切录像
			Set_Osd_PhotoRecord(OsdRun_Mode);
			OsdRefresh_Family[_PhotoRecord].Refresh_Flag = Refresh_yes;
		
			OsdRefresh_Family[_VL_PR].Data = 1; //拍照录像模式启动
			//DecToHexToAscii(OsdRefresh_Family[_PR].Data, 0, OsdRefresh_Family[_PR].Module_addr, 1);
			OsdRefresh_Family[_VL_PR].Module_addr[0] = osd_ON;
			OsdRefresh_Family[_VL_PR].Module_addr[1] = osd_NONE;
			OsdRefresh_Family[_VL_PR].Module_addr[2] = '\r';
			Rec_ON();//开始录像
			break;
		
		case _Infrared:
			OsdRun_Mode = _RecordMode;//切录像
			Set_Osd_PhotoRecord(OsdRun_Mode);
			OsdRefresh_Family[_PhotoRecord].Refresh_Flag = Refresh_yes;
		
			OsdRefresh_Family[_IR_PR].Data = 1; //拍照录像模式启动
			//DecToHexToAscii(OsdRefresh_Family[_PR].Data, 0, OsdRefresh_Family[_PR].Module_addr, 1);
			OsdRefresh_Family[_IR_PR].Module_addr[0] = osd_ON;
			OsdRefresh_Family[_IR_PR].Module_addr[1] = osd_NONE;
			OsdRefresh_Family[_IR_PR].Module_addr[2] = '\r';
			Rec_ON();//开始录像
			break;
		
		default :
			break;
	}
		
	return 1;
}

uint8_t KEY_MENU_LONG_PRESS_HOLD_Handler(void *btn)
{
	if(MenuLevel != _MainMenu) //菜单级别
		{
			return 1;
		}
    // do something...
		return 1;
}




uint8_t KEY_FUNC_SINGLE_Click_Handler(void *btn)
{
	uint8_t ClearScreenQueue;
    // do something...
		switch(MenuLevel)
		{
			case _MainMenu://进入配置菜单首页
				MenuLevel = _ConfigMenu;
				if(OsdLight_Mode == _Infrared)
				{
#if WiFi_Flag					
					OsdRefresh_Family[_IR_Wifi].Refresh_Flag = Refresh_yes;
#endif					
					OsdRefresh_Family[_IR_PR].Refresh_Flag = Refresh_yes;
					ConfigMenu_IR_OsdShowON();
					ConfigMenuPra = _IR_Brightness;//初始化配置菜单状态
				}
				else if(OsdLight_Mode == _Daylight)
				{
#if WiFi_Flag					
					OsdRefresh_Family[_VL_Wifi].Refresh_Flag = Refresh_yes;
#endif						
					OsdRefresh_Family[_VL_PR].Refresh_Flag = Refresh_yes;
					ConfigMenu_VL_OsdShowON();
					ConfigMenuPra = _VL_Brightness;//初始化配置菜单状态
				}
				break;
				
			case _ConfigMenu:	
					MenuLevel = _ParameterSet;
				break;
			
			case _ParameterSet:
				MenuLevel = _ConfigMenu;
				break;
			
			default:
				break;
		}
		
		return 1;
}


// KEY_Func 按键回调函数
uint8_t KEY_FUNC_DOUBLE_Click_Handler(void *btn)
{
	if(MenuLevel != _MainMenu) //菜单级别
		{
			return 1;
		}
	// do something...
	switch(OsdLight_Mode)
	{
		case _Daylight:
			switch(Osd_Daylight_ColorMode)
			{
				case _Auto://自动
					Osd_Daylight_ColorMode++;
					Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
					OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
					Uart6Send(VL_Mode_Defog_OFF_Cmd,MyStrlen(VL_Mode_Defog_OFF_Cmd));
					Uart6Send(VL_Mode_Day_Cmd,MyStrlen(VL_Mode_Day_Cmd));
					break;
				case _Day://彩色
					Osd_Daylight_ColorMode++;
					Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
					OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
					Uart6Send(VL_Mode_Defog_ON_Cmd,MyStrlen(VL_Mode_Defog_ON_Cmd));
					Uart6Send(VL_Mode_Defog_Low_Cmd,MyStrlen(VL_Mode_Defog_Low_Cmd));
					break;
				case _Defog_Low://透雾
					Osd_Daylight_ColorMode ++;
					Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
					OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
					Uart6Send(VL_Mode_Defog_ON_Cmd,MyStrlen(VL_Mode_Defog_ON_Cmd));
					Uart6Send(VL_Mode_Defog_Mid_Cmd,MyStrlen(VL_Mode_Defog_Mid_Cmd));
					break;
				case _Defog_Mid://透雾
					Osd_Daylight_ColorMode ++;
					Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
					OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
					Uart6Send(VL_Mode_Defog_ON_Cmd,MyStrlen(VL_Mode_Defog_ON_Cmd));
					Uart6Send(VL_Mode_Defog_Hig_Cmd,MyStrlen(VL_Mode_Defog_Hig_Cmd));
					break;
				case _Defog_Hig://透雾
					Osd_Daylight_ColorMode ++;
					Osd_Daylight_ColorMode = _Night;
					Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
					OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
					Uart6Send(VL_Mode_Defog_OFF_Cmd,MyStrlen(VL_Mode_Defog_OFF_Cmd));
					Uart6Send(VL_Mode_Night_Cmd,MyStrlen(VL_Mode_Night_Cmd));
					break;
				case _Night://黑白
					Osd_Daylight_ColorMode = _Auto;
					Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
					OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
					Uart6Send(VL_Mode_Defog_OFF_Cmd,MyStrlen(VL_Mode_Defog_OFF_Cmd));
					Uart6Send(VL_Mode_Auto_Cmd,MyStrlen(VL_Mode_Auto_Cmd));
					break;
				default:
					break;
				
			}
			break;
			
			case _Infrared:
				Osd_Infrared_ColorMode ++;
			switch(Osd_Infrared_ColorMode)
			{
				case _WhiteHot://白热
					OsdRefresh_Family[_IR_Polar].Data =	Osd_Infrared_ColorMode;
					Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
					OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
					Uart3Send(IR_Polar_WHot_Cmd,MyStrlen(IR_Polar_WHot_Cmd));
					break;
				case _BlackHot://黑热
					//Osd_Infrared_ColorMode ++;
					OsdRefresh_Family[_IR_Polar].Data =	Osd_Infrared_ColorMode;
					Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
					OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
					Uart3Send(IR_Polar_BHot_Cmd,MyStrlen(IR_Polar_BHot_Cmd));
					break;
#if ChengDu				
				case _Rainbow://彩红
					//Osd_Infrared_ColorMode ++;
					OsdRefresh_Family[_IR_Polar].Data =	Osd_Infrared_ColorMode;
					Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
					OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
					Uart3Send(IR_Polar_RainBow_Cmd,MyStrlen(IR_Polar_RainBow_Cmd));
					break;
#elif BT656
			
#endif				
				case _Iron://热金属
					//Osd_Infrared_ColorMode ++;
					OsdRefresh_Family[_IR_Polar].Data =	Osd_Infrared_ColorMode;
					Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
					OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
					Uart3Send(IR_Polar_Iron_Cmd,MyStrlen(IR_Polar_Iron_Cmd));
					break;
				case _GreenHot://绿热
					//Osd_Infrared_ColorMode = _GreenHot;
					OsdRefresh_Family[_IR_Polar].Data = Osd_Infrared_ColorMode,
					Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
					OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
					Uart3Send(IR_Polar_Green_Cmd,MyStrlen(IR_Polar_Green_Cmd));
					break;
				default:
					Osd_Infrared_ColorMode = _WhiteHot;
					OsdRefresh_Family[_IR_Polar].Data =	Osd_Infrared_ColorMode;
					Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
					OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
					Uart3Send(IR_Polar_WHot_Cmd,MyStrlen(IR_Polar_WHot_Cmd));
					break;
			}
			

				
		default :
			break;
	}
	return 1;
}






//长按切换 红外白光模式/退出菜单
uint8_t KEY_FUNC_LONG_PRESS_START_Handler(void *btn)
{
	static _Bool ClearOsdScreen;
	uint8_t ClearScreenQueue;

	bool state;
    // do something...
	if(MenuLevel != _MainMenu) //菜单级别
	{
		MenuLevel = _MainMenu;
		ClearScreenQueue = 0;//只清屏
		xQueueSend(Osd_ClearScreen_QueueHandle,&ClearScreenQueue,0);
		CursorReset_OsdShow();//擦除各个位置的光标
		ConfigMenu_OsdShowOFF();//擦除配置界面
	
		return 1;
	}
	
	
  if(MenuLevel == _MainMenu) //菜单级别
	{
		switch(OsdLight_Mode)
		{
			case _Daylight:
				//切红外把所有白光要展示的模块清遍
				StopLoadingContinueTimer();
			
				EraseDaylightOsdShow();
				//Uart3Send((uint8_t*)Enter_click,10);
				Set_Osd_LightMode(_Infrared);
				OsdLight_Mode = _Infrared;	//红外
        EraseLoading();//清洗描线位置显示内容，防止速切时候，图形粘贴现象
    		Infrared_AmplifierReduce_OsdShow(IR_AmplifierReduce_Date);
				InfraredOsdShow();
				//放大倍数
				IR_ZoomMCheck(IR_ZOOM_Cmd);
#if ChengDu 

				Uart3Send(IR_DNR_Cmd,MyStrlen(IR_ZOOM_Cmd));
#elif BT656
			    Uart3Send(IR_OutDoor_OFF_Cmd,MyStrlen(IR_OutDoor_OFF_Cmd));
			
			    Uart3Send(IR_Hot_Point_OFF_Cmd,MyStrlen(IR_Hot_Point_OFF_Cmd));

			
#endif
		

				OsdRefresh_Family[_IR_Zoom].Refresh_Flag = Refresh_yes;
				SetIRmode();
			
				switch(OsdRefresh_Family[_IR_Polar].Data)
				{
						case _WhiteHot:
							Osd_Infrared_ColorMode = _WhiteHot;
							Uart3Send(IR_Polar_WHot_Cmd,MyStrlen(IR_Polar_WHot_Cmd));
							break;
						case _BlackHot:
							Osd_Infrared_ColorMode = _BlackHot;
							Uart3Send(IR_Polar_BHot_Cmd,MyStrlen(IR_Polar_BHot_Cmd));
							break;
#if ChengDu 							
						case _Rainbow:
							Osd_Infrared_ColorMode = _Rainbow;
							//开启rainbow模式
							Uart3Send(IR_Polar_RainBow_Cmd,MyStrlen(IR_Polar_RainBow_Cmd));
							break;
#elif BT656
						
							
#endif
						case _Iron:
							Osd_Infrared_ColorMode = _Iron;
							Uart3Send(IR_Polar_Iron_Cmd,MyStrlen(IR_Polar_Iron_Cmd));
							break;
						case _GreenHot:
							Osd_Infrared_ColorMode = _GreenHot;
							Uart3Send(IR_Polar_Green_Cmd,MyStrlen(IR_Polar_Green_Cmd));
							break;
						default:
							break;					
				}
			    Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
								
				OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
				break;
				
			case _Infrared:
				//切白光把所有红外要展示的模块清遍
				EraseInfraredOsdShow();
				Set_Osd_LightMode(_Daylight);
				OsdLight_Mode = _Daylight;	//白光
				DaylightOsdShow();
				SetVLmode();
				OsdRefresh_Family[_VL_Mode].Data = _Day;
			
				VL_AmplifierReduce_Date = _VL_AmplifierReduce_1;
				Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
				xQueueSend(Zoom_QueueHandle,&state,0);
//			    OsdRefresh_Family[_AmplifierReduce].Refresh_Flag = Refresh_yes;
		
				switch(OsdRefresh_Family[_VL_Mode].Data)
				{
						case _Auto:
							Osd_Daylight_ColorMode = _Auto;
							//Uart6Send(VL_Mode_Defog_OFF_Cmd,MyStrlen(VL_Mode_Defog_OFF_Cmd));
							//Uart6Send(VL_Mode_Auto_Cmd,MyStrlen(VL_Mode_Auto_Cmd));
							break;
						case _Day:
							Osd_Daylight_ColorMode = _Day;
							//Uart6Send(VL_Mode_Defog_OFF_Cmd,MyStrlen(VL_Mode_Defog_OFF_Cmd));
							//Uart6Send(VL_Mode_Day_Cmd,MyStrlen(VL_Mode_Day_Cmd));
							break;
						case _Defog_Low:
							Osd_Daylight_ColorMode = _Defog_Low;
							//Uart6Send(VL_Mode_Defog_ON_Cmd,MyStrlen(VL_Mode_Defog_ON_Cmd));
							//Uart6Send(VL_Mode_Defog_Low_Cmd,MyStrlen(VL_Mode_Defog_Low_Cmd));
							break;
						case _Defog_Mid:
							Osd_Daylight_ColorMode = _Defog_Mid;
							//Uart6Send(VL_Mode_Defog_ON_Cmd,MyStrlen(VL_Mode_Defog_ON_Cmd));
							//Uart6Send(VL_Mode_Defog_Mid_Cmd,MyStrlen(VL_Mode_Defog_Mid_Cmd));
							break;
						case _Defog_Hig:
							Osd_Daylight_ColorMode = _Defog_Hig;
							//Uart6Send(VL_Mode_Defog_ON_Cmd,MyStrlen(VL_Mode_Defog_ON_Cmd));
							//Uart6Send(VL_Mode_Defog_Hig_Cmd,MyStrlen(VL_Mode_Defog_Hig_Cmd));
							break;
						case _Night:
							Osd_Daylight_ColorMode = _Night;
							//Uart6Send(VL_Mode_Defog_OFF_Cmd,MyStrlen(VL_Mode_Defog_OFF_Cmd));
							//Uart6Send(VL_Mode_Night_Cmd,MyStrlen(VL_Mode_Night_Cmd));
							break;
						default:
							Osd_Daylight_ColorMode = _Auto;
							OsdRefresh_Family[_VL_Mode].Data = Osd_Daylight_ColorMode;
							//Uart6Send(VL_Mode_Defog_OFF_Cmd,MyStrlen(VL_Mode_Defog_OFF_Cmd));
							//Uart6Send(VL_Mode_Auto_Cmd,MyStrlen(VL_Mode_Auto_Cmd));
							break;					
				}
						
				Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
				ShowLoading();
				OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
	//					OsdRefresh_Family[_VL_Mode].Refresh_Flag = Refresh_yes;
				break;
								
			default	:
				break;
		}
	}
	return 1;
}



uint8_t KEY_FUNC_LONG_PRESS_HOLD_Handler(void *btn)
{
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}
    // do something...
		return 1;
}

uint8_t IR_Zoom;


// KEY_Up 按键回调函数
uint8_t KEY_UP_SINGLE_Click_Handler(void *btn)
{
		bool state;
	
		if(MenuLevel == _ConfigMenu)
		{
			ConfigMenuPra-=2;
			CursorUp(&ConfigMenuPra);
			return 1;
		}
	
		if(MenuLevel == _ParameterSet) //菜单级别
		{
			CursorRight(&ConfigMenuPra);
			return 1;
		}
//		if(OsdLight_Mode != _Daylight) 
//		{
//			return 2;
//		}
		// do something...

		if(OsdLight_Mode == _Daylight)
		{
#if VL_MC_105Q

			if(AmplifierReduce_Date < 15)
			{
					MotorStop_Source = _No_Stop;
					AmplifierReduce_Date ++;
					AmplifierReduce_OsdShow(AmplifierReduce_Date);
					VL_Zoom_DZoomSet(AmplifierReduce_Date);
					
					state = true;
					xQueueSend(Zoom_QueueHandle,&state,0);
			}
#endif
#if VL_YT_3578_HD

			if(VL_AmplifierReduce_Date < _VL_AmplifierReduce_16)
			{
				VL_AmplifierReduce_Date ++;
				Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
				VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);
				
				state = true;
				xQueueSend(Zoom_QueueHandle,&state,0);
			}
			else
			{
			    VL_AmplifierReduce_Date = _VL_AmplifierReduce_1;
				Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
				VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);

				state = true;
				xQueueSend(Zoom_QueueHandle,&state,0);
			}
#endif
			
		}
		else if(OsdLight_Mode == _Infrared)
		{
#if ChengDu			

      if(IR_AmplifierReduce_Date < _IR_AmplifierReduce_8)
				{
					if(IR_AmplifierReduce_Date == 1)
						IR_AmplifierReduce_Date = 0;
						
					IR_AmplifierReduce_Date += 2;
					Infrared_AmplifierReduce_OsdShow(IR_AmplifierReduce_Date);
					
					OsdRefresh_Family[_IR_Zoom].Refresh_Flag = Refresh_yes;
					IR_ZOOM_Cmd[10] = IR_AmplifierReduce_Date;
					IR_ZoomMCheck(IR_ZOOM_Cmd);
					Uart3Send(IR_ZOOM_Cmd,MyStrlen(IR_ZOOM_Cmd));
				}
				else
				{
					IR_AmplifierReduce_Date = 1;
					Infrared_AmplifierReduce_OsdShow(IR_AmplifierReduce_Date);
					OsdRefresh_Family[_IR_Zoom].Refresh_Flag = Refresh_yes;
					IR_ZOOM_Cmd[10] = IR_AmplifierReduce_Date;
					IR_ZoomMCheck(IR_ZOOM_Cmd);
					Uart3Send(IR_ZOOM_Cmd,MyStrlen(IR_ZOOM_Cmd));
				}
#elif BT656 

#endif			
		}
		
		return 1;
}


uint8_t KEY_UP_DOUBLE_Click_Handler(void *btn)
{	
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}
    // do something...
		return 1;
}
uint8_t KEY_UP_LONG_PRESS_START_Handler(void *btn)
{
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}
		
		if(MenuLevel == _MainMenu) //菜单级别
		{
			if(OsdLight_Mode == _Infrared) //红外模式下有效
			{
#if Motor_Flag
				MotorRun_Mode = _Foreward;
				MotorForwardReverse_OsdShow(MotorRun_Mode);
				OsdRefresh_Family[_ForwardReverse].Refresh_Flag = Refresh_yes;
				xQueueSend(ForewardReverse_QueueHandle,&MotorRun_Mode,0);//
#endif
			}
			
			
			return 1;
		}
    // do something...
		return 1;

}

uint8_t KEY_UP_LONG_PRESS_HOLD_Handler(void *btn)
{
		static uint16_t num = 0;
		bool state;
	
		if(MenuLevel == _MainMenu) //菜单级别
		{
			if(OsdLight_Mode == _Infrared) //红外模式下有效
			{
#if Motor_Flag
				MotorRun_Mode = _Foreward;
				MotorForwardReverse_OsdShow(MotorRun_Mode);
				OsdRefresh_Family[_ForwardReverse].Refresh_Flag = Refresh_yes;
				xQueueSend(ForewardReverse_QueueHandle,&MotorRun_Mode,0);//
#endif
			}
			else if(OsdLight_Mode == _Daylight)
			{
				KEY_Up_LONG_PRESS_HOLD_Flag = true;
				num++;
				if(num>100)
				{
					num = 0;
#if VL_MC_105Q
					AmplifierReduce_Date++;
					if(AmplifierReduce_Date >=_AmplifierReduce_16)
					{
						AmplifierReduce_Date = 15;
						//AmplifierReduce_Date = _AmplifierReduce_1;
		//				AmplifierReduce_OsdShow(16);
		//				xQueueSend(Zoom_QueueHandle,&state,0);
					}
					else
					{

						VL_Zoom_DZoomSet(AmplifierReduce_Date);
						AmplifierReduce_OsdShow(AmplifierReduce_Date);
						xQueueSend(Zoom_QueueHandle,&state,0);
					}
					
#elif VL_YT_3578_HD
			
					if(VL_AmplifierReduce_Date < _VL_AmplifierReduce_16)
					{
							VL_AmplifierReduce_Date ++;
							Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
						  VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);
							
							state = true;
							xQueueSend(Zoom_QueueHandle,&state,0);
					}
					else
					{
					  VL_AmplifierReduce_Date = _VL_AmplifierReduce_16;
						Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
						VL_Zoom_DZoomSet(VL_AmplifierReduce_Date);

						state = true;
						xQueueSend(Zoom_QueueHandle,&state,0);
					}
			
#endif			
				}
			}
			return 1;
		}
	
    // do something...
		return 1;
}

uint8_t KEY_UP_PRESS_UP(void *btn)
{
		if(MenuLevel == _MainMenu) //菜单级别
		{
#if Motor_Flag
			MotorRun_Mode = _MotorStop;
			MotorForwardReverse_OsdShow(_MotorStop);
			OsdRefresh_Family[_ForwardReverse].Refresh_Flag = Refresh_yes;
			xQueueSend(ForewardReverse_QueueHandle,&MotorRun_Mode,0);//
#endif
			return 1;
		}
	
    // do something...
		return 1;
}

// KEY_Down 按键回调函数
uint8_t KEY_DOWN_SINGLE_Click_Handler(void *btn)
{
		switch(MenuLevel)
		{
			case _MainMenu:
				switch(OsdLight_Mode)
					{
						case _Daylight:
							switch(Osd_Daylight_ColorMode)
							{
								case _Auto://自动
									Osd_Daylight_ColorMode++;
									Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
									OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
									Uart6Send(VL_Mode_Defog_OFF_Cmd,MyStrlen(VL_Mode_Defog_OFF_Cmd));
									Uart6Send(VL_Mode_Day_Cmd,MyStrlen(VL_Mode_Day_Cmd));
									break;
								case _Day://彩色
									Osd_Daylight_ColorMode++;
									Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
									OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
									Uart6Send(VL_Mode_Defog_ON_Cmd,MyStrlen(VL_Mode_Defog_ON_Cmd));
									Uart6Send(VL_Mode_Defog_Low_Cmd,MyStrlen(VL_Mode_Defog_Low_Cmd));
									break;
								case _Defog_Low://透雾
									Osd_Daylight_ColorMode ++;
									Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
									OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
									Uart6Send(VL_Mode_Defog_ON_Cmd,MyStrlen(VL_Mode_Defog_ON_Cmd));
									Uart6Send(VL_Mode_Defog_Mid_Cmd,MyStrlen(VL_Mode_Defog_Mid_Cmd));
									break;
								case _Defog_Mid://透雾
									Osd_Daylight_ColorMode ++;
									Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
									OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
									Uart6Send(VL_Mode_Defog_ON_Cmd,MyStrlen(VL_Mode_Defog_ON_Cmd));
									Uart6Send(VL_Mode_Defog_Hig_Cmd,MyStrlen(VL_Mode_Defog_Hig_Cmd));
									break;
								case _Defog_Hig://透雾
									Osd_Daylight_ColorMode ++;
									Osd_Daylight_ColorMode = _Night;
									Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
									OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
									Uart6Send(VL_Mode_Defog_OFF_Cmd,MyStrlen(VL_Mode_Defog_OFF_Cmd));
									Uart6Send(VL_Mode_Night_Cmd,MyStrlen(VL_Mode_Night_Cmd));
									break;
								case _Night://黑白
									Osd_Daylight_ColorMode = _Auto;
									Set_Osd_Daylight_ColorMode(Osd_Daylight_ColorMode);
									OsdRefresh_Family[_Daylight_ColorMode].Refresh_Flag = Refresh_yes;
									Uart6Send(VL_Mode_Defog_OFF_Cmd,MyStrlen(VL_Mode_Defog_OFF_Cmd));
									Uart6Send(VL_Mode_Auto_Cmd,MyStrlen(VL_Mode_Auto_Cmd));
									break;
								default:
									break;
								
							}
							break;
							
							case _Infrared:
								Osd_Infrared_ColorMode ++;
							switch(Osd_Infrared_ColorMode)
							{
								case _WhiteHot://白热
									OsdRefresh_Family[_IR_Polar].Data =	Osd_Infrared_ColorMode;
									Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
									OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
									Uart3Send(IR_Polar_WHot_Cmd,MyStrlen(IR_Polar_WHot_Cmd));
									break;
								case _BlackHot://黑热
									//Osd_Infrared_ColorMode ++;
									OsdRefresh_Family[_IR_Polar].Data =	Osd_Infrared_ColorMode;
									Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
									OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
									Uart3Send(IR_Polar_BHot_Cmd,MyStrlen(IR_Polar_BHot_Cmd));
									break;
				#if ChengDu				
								case _Rainbow://彩红
									//Osd_Infrared_ColorMode ++;
									OsdRefresh_Family[_IR_Polar].Data =	Osd_Infrared_ColorMode;
									Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
									OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
									Uart3Send(IR_Polar_RainBow_Cmd,MyStrlen(IR_Polar_RainBow_Cmd));
									break;
				#elif BT656
							
				#endif				
								case _Iron://热金属
									//Osd_Infrared_ColorMode ++;
									OsdRefresh_Family[_IR_Polar].Data =	Osd_Infrared_ColorMode;
									Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
									OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
									Uart3Send(IR_Polar_Iron_Cmd,MyStrlen(IR_Polar_Iron_Cmd));
									break;
								case _GreenHot://绿热
									//Osd_Infrared_ColorMode = _GreenHot;
									OsdRefresh_Family[_IR_Polar].Data = Osd_Infrared_ColorMode,
									Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
									OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
									Uart3Send(IR_Polar_Green_Cmd,MyStrlen(IR_Polar_Green_Cmd));
									break;
								default:
									Osd_Infrared_ColorMode = _WhiteHot;
									OsdRefresh_Family[_IR_Polar].Data =	Osd_Infrared_ColorMode;
									Set_Osd_Infrared_ColorMode(Osd_Infrared_ColorMode);
									OsdRefresh_Family[_Infrared_ColorMode].Refresh_Flag = Refresh_yes;
									Uart3Send(IR_Polar_WHot_Cmd,MyStrlen(IR_Polar_WHot_Cmd));
									break;
							}
							

								
						default :
							break;
					}
					
				
				break;
			case _ConfigMenu:
					ConfigMenuPra+=2;
					CursorDown(&ConfigMenuPra);
				break;
			case _ParameterSet:
					CursorLeft(&ConfigMenuPra);
				break;
			
			default:
				break;
		
		}

		return 1;
}



uint8_t KEY_DOWN_DOUBLE_Click_Handler(void *btn)
{
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}	
    // do something...
		return 1;
}



uint8_t KEY_DOWN_LONG_PRESS_START_Handler(void *btn)
{
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}
		
		if(MenuLevel == _MainMenu) //菜单级别
		{
			if(OsdLight_Mode == _Infrared) //红外模式下有效
			{
#if Motor_Flag
				MotorRun_Mode = _Reverse;
				MotorForwardReverse_OsdShow(MotorRun_Mode);
				OsdRefresh_Family[_ForwardReverse].Refresh_Flag = Refresh_yes;
				xQueueSend(ForewardReverse_QueueHandle,&MotorRun_Mode,0);//
#endif
			}
			
			return 1;
		}
    // do something...
		return 1;

}


uint8_t KEY_DOWN_LONG_PRESS_HOLD_Handler(void *btn)
{
	static uint16_t num;
	bool state;
	
		if(MenuLevel != _MainMenu) //菜单级别
		{
			return 1;
		}
		
		if(OsdLight_Mode == _Infrared) //红外模式下有效
		{
#if Motor_Flag
				MotorRun_Mode = _Reverse;
				MotorForwardReverse_OsdShow(MotorRun_Mode);
				OsdRefresh_Family[_ForwardReverse].Refresh_Flag = Refresh_yes;
				xQueueSend(ForewardReverse_QueueHandle,&MotorRun_Mode,0);//
#endif
		}
	
	
// do something...
		return 1;
}

uint8_t KEY_DOWN_PRESS_UP(void *btn)
{
		if(MenuLevel == _MainMenu) //菜单级别
		{
#if Motor_Flag
			MotorRun_Mode = _MotorStop;
			MotorForwardReverse_OsdShow(_MotorStop);
			OsdRefresh_Family[_ForwardReverse].Refresh_Flag = Refresh_yes;
			xQueueSend(ForewardReverse_QueueHandle,&MotorRun_Mode,0);//
#endif
			return 1;
		}
		if(KEY_Down_LONG_PRESS_HOLD_Flag == false)
		{
			return 0;
		}
	
    // do something...
		return 1;
}


//////////////////////////

// KEY_Up 按键回调函数
uint8_t KEY_Laser_SINGLE_Click_Handler(void *btn)
{
	uint8_t ClearScreenQueue;
	
	
		bool state;
	
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}

		if(Flag_LsserON ==false) //启动
		{
			StartDistanceTimer();
			Flag_LsserON = true;
			
			LaserPowerON();
			OsdRefresh_Family[_LaserFlag].Module_addr[0] = osd_Icon_Laser_1;
			OsdRefresh_Family[_LaserFlag].Module_addr[1] = osd_Icon_Laser_2;
			OsdRefresh_Family[_LaserFlag].Module_addr[2] = '\r';
			OsdRefresh_Family[_LaserFlag].Refresh_Flag = Refresh_yes;
			return 2;
		}
		
		//白光模式下放大倍数调到10倍数
//		if(OsdLight_Mode == _Daylight) 
//		{
//			StartDistanceTimer();
//			VL_Zoom_DZoomSet(10);
//			VL_AmplifierReduce_Date = _VL_AmplifierReduce_10;
//			Daylight_AmplifierReduce_OsdShow(VL_AmplifierReduce_Date);
//			xQueueSend(Zoom_QueueHandle,&state,0);
//		}
		//测距
		DistanceMesureOne();
		//闪烁
		xQueueSend(Laser_QueueHandle,&ClearScreenQueue,0); //激光图标闪烁
		OsdRefresh_Family[_LaserFlag].Refresh_Flag = Refresh_yes;
		return 1;
}

uint8_t KEY_Laser_DOUBLE_Click_Handler(void *btn)
{	
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}
    // do something...
		return 1;
}
uint8_t KEY_Laser_LONG_PRESS_START_Handler(void *btn)
{
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}
    // do something...
		LaserPowerOFF();
		OsdRefresh_Family[_LaserFlag].Module_addr[0] = osd_NONE;
		OsdRefresh_Family[_LaserFlag].Module_addr[1] = osd_NONE;
		OsdRefresh_Family[_LaserFlag].Module_addr[2] = '\r';
		OsdRefresh_Family[_LaserFlag].Refresh_Flag = Refresh_yes;
		
		OsdRefresh_Family[_Distance].Module_addr[0] = osd_NONE;
		OsdRefresh_Family[_Distance].Module_addr[1] = osd_NONE;
		OsdRefresh_Family[_Distance].Module_addr[2] = osd_NONE;
		OsdRefresh_Family[_Distance].Module_addr[3] = osd_NONE;
		OsdRefresh_Family[_Distance].Module_addr[4] = osd_NONE;
		OsdRefresh_Family[_Distance].Refresh_Flag = Refresh_yes;
		Flag_LsserON = false;
		return 1;

}
uint8_t KEY_Laser_LONG_PRESS_HOLD_Handler(void *btn)
{
		static uint16_t num = 0;
		bool state;
	
		if(MenuLevel == _ConfigMenu) //菜单级别
		{
			return 1;
		}

		return 1;
}

uint8_t KEY_Laser_PRESS_UP(void *btn)
{
	bool state;
	
		
		return 1;
}


#endif






